VBA: Formatting a series line in chart

Will_B

Board Regular
Joined
Mar 4, 2009
Messages
79
In VBA, how do I access the line object of a chart's SeriesCollection(n)? Excel's Help frightens me with "There’s no object that represents a single series line...". My immediate need is to make Series1 and Series2 be dotted lines (xlDot) for a great number of charts. Hence my desire for a VBA solution. I thought it might be something like:

myChart.SeriesCollection(1).Format.Line = xlDot
myChart.SeriesCollection(2).Format.Line = xlDot

Is there a solution?
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
myChart.SeriesCollection(1).Border.LineStyle = xlDot
myChart.SeriesCollection(2).Border.LineStyle = xlDot

I believe (try recording macros to see how to make things change -- I selected my chart and changed series 1 and 2 to dot, and got this code):
Code:
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 3/11/2009 by ------
'

'
    ActiveChart.SeriesCollection(1).Select
    With Selection.Border
        .ColorIndex = 57
        .Weight = xlThin
        .LineStyle = xlDot
    End With
    With Selection
        .MarkerBackgroundColorIndex = xlAutomatic
        .MarkerForegroundColorIndex = xlAutomatic
        .MarkerStyle = xlAutomatic
        .Smooth = False
        .MarkerSize = 5
        .Shadow = False
    End With
    ActiveChart.SeriesCollection(2).Select
    With Selection.Border
        .ColorIndex = 57
        .Weight = xlThin
        .LineStyle = xlDot
    End With
    With Selection
        .MarkerBackgroundColorIndex = xlAutomatic
        .MarkerForegroundColorIndex = xlAutomatic
        .MarkerStyle = xlAutomatic
        .Smooth = False
        .MarkerSize = 5
        .Shadow = False
    End With
End Sub
 
Upvote 0
Thanks, Sal. However, I can't get this to work in my code just yet, but at least now I get no error message. I'll post the solution once I get my code working. Thanks!
 
Upvote 0
Try recording a macro to do what you want, and see what the results are. It may have different syntax depending on graph type.
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,543
Members
449,089
Latest member
davidcom

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