VBA for "if data series is last series in the chart, change the color of that data series"?

ajjava

Board Regular
Joined
Dec 11, 2018
Messages
57
Office Version
  1. 365
Platform
  1. Windows
I have the following code that changes properties of individual data series in a chart.
It's currently written to change the data series format to BEVEL style and the color ORANGE (msoThemeColorAccent6).

I'd like to update it to include some logic that says, "ONLY if this is the LAST data series in the chart, make this series color msoThemeColorAccent6".

You'll note that I currently have the code for changing the color of a series in my procedure. I'm just trying to make it smarter.

Code:
Sub chartSeriesColor(objChart As Object)

    Dim seriesColl As Series
    Dim chartType As String
    Dim i As Long
    
    'Identify objChart parameter if it has a Chart type (chart sheet) or ChartObject (embedded chart)
    chartType = TypeName(objChart)
    
    'Count how many series the chart has
    
    'Note the difference between the assignments
    If chartType = "Chart" Then
        'Chart sheets
        countOfSeries = objChart.SeriesCollection.Count
    Else
        'Chart objects (embedded charts)
        countOfSeries = objChart.Chart.SeriesCollection.Count
    End If
    
    
    
    'Looping through all the chart series
    For i = 1 To countOfSeries
        
        'Note the difference between the assignments
        If chartType = "Chart" Then
            'Chart sheets
            Set seriesColl = objChart.SeriesCollection(i)
        Else
            'Chart objects (embedded charts)
            Set seriesColl = objChart.Chart.SeriesCollection(i)
        End If
        
        'change whatever property of the data series here
        
        With seriesColl.Format.ThreeD
            .BevelTopType = msoBevelCircle
            .BevelTopInset = 6
            .BevelTopDepth = 6
        End With
        
        
      
        With seriesColl.Format.Fill
            .ForeColor.ObjectThemeColor = msoThemeColorAccent6
            .ForeColor.TintAndShade = 0
            .ForeColor.Brightness = 0
            .Transparency = 0
            .Solid
        End With
     
        
        
        'clear seriesColl variable
        Set seriesColl = Nothing
        


    Next i
End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
I should add - this procedure is being called by another procedure that executes the code on ALL charts of ALL sheets of the active workbook.
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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