Color Charts in a specific style

bobsell

New Member
Joined
Jul 15, 2011
Messages
12
Hi guys,


I am yet again puzzled by VBA.
I wrote a script that colors the lines in a chart a specific color based on the model number in the Series Name. I have about 250 models that this macro has to set different criteria for.

BUT it somehow does not want to work on all cases, and sometimes works only selectively.

Here is the script:
Code:
Dim j As Integer
j = ActiveChart.Legend.LegendEntries.Count

    For i = 1 To j
    With ActiveChart
        Select Case .SeriesCollection(i).Name
        
            Case "KDL-32BX300"
                With .SeriesCollection(i)
                .Border.ColorIndex = 2
                .Border.Weight = 1
                .Border.LineStyle = xlDashDot
                .MarkerStyle = False
                .Smooth = False
                .Shadow = False
                .MarkerBackgroundColorIndex = False
                .MarkerForegroundColorIndex = False
                End With
                
            Case "KDL-32BX400"
                With .Legend.LegendEntries(j).LegendKey
                .Border.ColorIndex = 2
                .Border.Weight = 2
                .Border.LineStyle = xlDashDot
                .MarkerStyle = False
                .Smooth = False
                .Shadow = False
                .MarkerBackgroundColorIndex = False
                .MarkerForegroundColorIndex = False
                End With
                
            Case "KDL-32EX402"
                With .Legend.LegendEntries(j).LegendKey
                .Border.ColorIndex = 2
                .Border.Weight = 2
                .Border.LineStyle = xlDashDot
                .MarkerStyle = False
                .Smooth = False
                .Shadow = False
                .MarkerBackgroundColorIndex = False
                .MarkerForegroundColorIndex = False
                End With

        End Select
        End With
    Next
End With

Please Help!!
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
I fixed some ridiculous errors, but the code still does not color the lines.
It just removes the colors of each line.

Code:
Dim j As Integer
j = ActiveChart.SeriesCollection.Count

    For i = 1 To j
    With ActiveChart
        Select Case .SeriesCollection(i).Name
        
            Case "KDL-32BX300"
                With .SeriesCollection(i)
                .Border.ColorIndex = 2
                .Border.Weight = 1
                .Border.LineStyle = xlDashDot
                .MarkerStyle = False
                .Smooth = False
                .Shadow = False
                .MarkerBackgroundColorIndex = False
                .MarkerForegroundColorIndex = False
                End With
                
            Case "KDL-32BX400"
                With .SeriesCollection(i)
                .Border.ColorIndex = 2
                .Border.Weight = 2
                .Border.LineStyle = xlDashDot
                .MarkerStyle = False
                .Smooth = False
                .Shadow = False
                .MarkerBackgroundColorIndex = False
                .MarkerForegroundColorIndex = False
                End With
                
            Case "KDL-32EX402"
                With .SeriesCollection(i)
                .Border.ColorIndex = 2
                .Border.Weight = 2
                .Border.LineStyle = xlDashDot
                .MarkerStyle = False
                .Smooth = False
                .Shadow = False
                .MarkerBackgroundColorIndex = False
                .MarkerForegroundColorIndex = False
                End With

        End Select
        End With
    Next
End With
 
Upvote 0
Nevermind,
I fixed it.

The previous code was not coloring the line because there was no data for it. :)
 
Upvote 0

Forum statistics

Threads
1,224,591
Messages
6,179,767
Members
452,940
Latest member
rootytrip

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