Macro to format charts in excel

QuestionBaker

Board Regular
Joined
Apr 12, 2019
Messages
106
Office Version
  1. 365
Platform
  1. Windows
I am working on macro to format excel charts so they can be used in power points.
A given chart can be formatted in multiple different ways (depends on the layout required in the ppt)

I want to add different buttons for running different macros. The macro will run only on selected chart and none of the other charts will be affected.
I want help in identifying which is (are) the currently selected charts so that the code can work on it.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
The following code will process either the active chart or all of the selected charts. The first procedure determines which chart or charts are selected, and then passes the active chart or each one of the selected charts to a second routine to do the formatting.

VBA Code:
Option Explicit

Sub FormatCharts()

    Dim obj As Object

    If Not ActiveChart Is Nothing Then
        FormatSingleChart ActiveChart
    Else
        For Each obj In Selection
            If TypeName(obj) = "ChartObject" Then
                FormatSingleChart obj.Chart
            End If
        Next obj
    End If
  
End Sub


Sub FormatSingleChart(ByVal cht As Chart)

    'format your chart
    With cht
        'etc
        '
        '
    End With
  
End Sub

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,369
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top