Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 562
  • Last Modified:

How to Format Excel Chart line color in VBA

I have an excel chart I'm trying to reformat. The series collection alternates between stacked and line charts and I want to color the lines the so that each line is the same color as the prior stacked series.
To that extent I tried:
        Dim lColor As Long
        For ctr = 2 To 10 Step 2
            lColor = Sheets(sSheet).ChartObjects("Chart 1").Chart.SeriesCollection(ctr - 1).Border.ColorIndex
            Sheets(sSheet).ChartObjects("Chart 1").Chart.SeriesCollection(ctr).Border.ColorIndex = lColor
        Next ctr

Open in new window


but it doesn't seem to work. Does anyone have any ideas?
0
stopher2475
Asked:
stopher2475
  • 2
1 Solution
 
telyni19Commented:
Try Color instead of ColorIndex, and Interior instead of Border for the stacked series.
Sub ChartColorTest()
    Dim lColor As Long
    For ctr = 2 To 10 Step 2
        lColor = Sheets(sSheet).ChartObjects("Chart 1").Chart.SeriesCollection(ctr - 1).Interior.Color
        Sheets(sSheet).ChartObjects("Chart 1").Chart.SeriesCollection(ctr).Border.Color = lColor
    Next ctr
End Sub

Open in new window

0
 
stopher2475Author Commented:
Will give it a shot in the AM.
0
 
stopher2475Author Commented:
That seems to have done the trick.
Thanks for the help!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now