ajjava
Board Regular
- Joined
- Dec 11, 2018
- Messages
- 57
- Office Version
- 365
- Platform
- 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.
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