Hi all VBA experts out there, I have a chart where a macro is able to change the series color using case select.
However when I try to introduce wild card into this case select, I am hitting a road block.
Below is what I got working, as you can see I would like to introduce a wild card instead of specifying every case "ABC", "Abc 123", etc
I have also posted my failed attempt at introducing the wildcard. It would be great to understand exactly why it doesn't work.
Error occurs at For Each rng In ActiveChart.SeriesCollection(x).Name
However when I try to introduce wild card into this case select, I am hitting a road block.
Below is what I got working, as you can see I would like to introduce a wild card instead of specifying every case "ABC", "Abc 123", etc
I have also posted my failed attempt at introducing the wildcard. It would be great to understand exactly why it doesn't work.
Error occurs at For Each rng In ActiveChart.SeriesCollection(x).Name
Code:
Sub ChangeMarqChartLColour()
Dim x As Integer
Dim i As Integer
ActiveSheet.ChartObjects("Marq_ChartL").Activate
i = ActiveChart.SeriesCollection.Count
For x = 1 To i
Select Case ActiveChart.SeriesCollection(x).Name
Case "ABC", "Abc 123", "Abc 234", "Abc 345", "Abc 456", "Abc 567", "Abc 678", "Abc789"
ActiveChart.SeriesCollection(x).Format.Line.ForeColor.RGB = RGB(255, 0, 0)
Case "CCC", "Ccc 123", "Ccc 234"
ActiveChart.SeriesCollection(x).Format.Line.ForeColor.RGB = RGB(49, 134, 155)
Case Else
ActiveChart.SeriesCollection(x).Format.Line.ForeColor.RGB = RGB(0, 0, 0)
End Select
Next
Next
x = Clear
i = Clear
End Sub
'second version
Sub ChangeMarqChartRColour()
Dim x As Integer
Dim i As Integer
Dim rng As Range
ActiveSheet.ChartObjects("Marq_ChartR").Activate
i = ActiveChart.SeriesCollection.Count
For x = 1 To i
For Each rng In ActiveChart.SeriesCollection(x).Name
Select Case True
Case rng.Value Like "*ABC*"
ActiveChart.SeriesCollection(x).Format.Line.ForeColor.RGB = RGB(255, 0, 0)
Case rng.Value Like "*CCC*"
ActiveChart.SeriesCollection(x).Format.Line.ForeColor.RGB = RGB(49, 134, 155)
Case Else
ActiveChart.SeriesCollection(x).Format.Line.ForeColor.RGB = RGB(0, 0, 0)
End Select
Next
Next
x = Clear
i = Clear
End Sub