Solved

How to Format Excel Chart line color in VBA

Posted on 2011-03-16
3
505 Views
Last Modified: 2012-05-11
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
Comment
Question by:stopher2475
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
telyni19 earned 500 total points
ID: 35152332
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
 
LVL 2

Author Comment

by:stopher2475
ID: 35177814
Will give it a shot in the AM.
0
 
LVL 2

Author Closing Comment

by:stopher2475
ID: 35181022
That seems to have done the trick.
Thanks for the help!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now