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

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Sal Paradise

Well-known Member
Joined
Oct 23, 2006
Messages
2,457
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
 

Will_B

Board Regular
Joined
Mar 4, 2009
Messages
79
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!
 

Sal Paradise

Well-known Member
Joined
Oct 23, 2006
Messages
2,457
Try recording a macro to do what you want, and see what the results are. It may have different syntax depending on graph type.
 

Forum statistics

Threads
1,144,697
Messages
5,725,814
Members
422,643
Latest member
elwayfan446

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
Top