Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel VBA - How do you set line style for chart series?

Tags:

excel

vba

charts

I would like the plot lines in a chart to be either solid, circle dot, or square dot based upon a certain criteria specified by the user. I can successfully set the line color and marker style for the plot using a macro, but I cannot seem to find the object which holds the value for the plot line style property. I have tried using the record macro function, but changing the line style in the properties windows does not show up in the code, and running the recorded macro has no effect.

Any help is greatly appreciated!

like image 424
user1130306 Avatar asked Dec 21 '22 03:12

user1130306


2 Answers

YourChartSeries.Border.LineStyle = [some value from the XlLineStyle enumeration]

UPDATE: recording in XL 2010 I get this -

ActiveChart.SeriesCollection(1).Select
With Selection.Format.Line
    .Visible = msoTrue
    .DashStyle = msoLineSysDot
End With
ActiveChart.SeriesCollection(2).Select
With Selection.Format.Line
    .Visible = msoTrue
    .DashStyle = msoLineSysDash
End With

Which might be what you're looking for.

like image 158
Tim Williams Avatar answered Dec 27 '22 06:12

Tim Williams


Create a chart with 255 data series, run the code (and do other formatting as necessary). Then save it as a template.

Sub dd()

Dim wb As Workbook
Set wb = Application.ActiveWorkbook

Dim myChart As Chart
Set myChart = wb.Charts("Chart5")

Dim mySeries As series

For Each mySeries In myChart.SeriesCollection
    mySeries.Format.Line.Weight = 1#
Next

End Sub
like image 38
jaykay Avatar answered Dec 27 '22 04:12

jaykay