Macro to format charts in excel

QuestionBaker

New Member
Joined
Apr 12, 2019
Messages
45
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.
 

Some videos you may like

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,403
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!
 

Watch MrExcel Video

Forum statistics

Threads
1,118,774
Messages
5,574,157
Members
412,574
Latest member
shadowfighter666
Top