ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA chart formatting (https://www.excelbanter.com/excel-programming/414870-vba-chart-formatting.html)

Arne

VBA chart formatting
 
How can I format individual serieslines within a chart group?

Why does this not change the LineStyles?

Set ChtSht = Worksheets("Sheet1")
Dim ChtObj As ChartObject


For Each ChtObj In ChtSht.ChartObjects

Debug.Print "Chart Object #: " & ChtObj.Index

ChtObj.Activate
Debug.Print "Number of Chart Groups is: " &
ActiveChart.ChartGroups.Count
'Debug.Print ChtObj.ChartGroups.Count 'object doesn't support property
or method

Debug.Print "Number of series is: " & ActiveChart.SeriesCollection.Count

ActiveChart.ChartGroups(1).HasSeriesLines = True

With ActiveChart.ChartGroups(1).SeriesLines.Border
.LineStyle = xlDashDotDot 'unable to set LineStyle property of Border
.Weight = xlMedium
.ColorIndex = 3
End With

Next ChtObj

The immediate widow:

Chart Object #: 1
Number of Chart Groups is: 1
Number of series is: 4




Peter T

VBA chart formatting
 
There's not much that's right with your code to work with or guess what you
are doing overall. OK a guess - you want to format the first series, which
is a line type, in each chart to have a red border

Sub test()
Dim i As Long
Dim cht As Chart
Dim sr As Series

For i = 1 To ActiveSheet.ChartObjects.Count
Set cht = ActiveSheet.ChartObjects(i).Chart
Set sr = cht.SeriesCollection(1)
' or if there's a particular need to work with chartgroups(1)
'Set sr = cht.ChartGroups(1).SeriesCollection(1)

sr.Border.ColorIndex = 3

' this will error if the series does not have markers
'sr.MarkerBackgroundColorIndex = 3
'sr.MarkerForegroundColorIndex = 3

Next

End Sub

Regards,
Peter T


"Arne" wrote in message
...
How can I format individual serieslines within a chart group?

Why does this not change the LineStyles?

Set ChtSht = Worksheets("Sheet1")
Dim ChtObj As ChartObject


For Each ChtObj In ChtSht.ChartObjects

Debug.Print "Chart Object #: " & ChtObj.Index

ChtObj.Activate
Debug.Print "Number of Chart Groups is: " &
ActiveChart.ChartGroups.Count
'Debug.Print ChtObj.ChartGroups.Count 'object doesn't support
property
or method

Debug.Print "Number of series is: " &
ActiveChart.SeriesCollection.Count

ActiveChart.ChartGroups(1).HasSeriesLines = True

With ActiveChart.ChartGroups(1).SeriesLines.Border
.LineStyle = xlDashDotDot 'unable to set LineStyle property of
Border
.Weight = xlMedium
.ColorIndex = 3
End With

Next ChtObj

The immediate widow:

Chart Object #: 1
Number of Chart Groups is: 1
Number of series is: 4






Arne

VBA chart formatting
 
Peter,

Using the Border property of SeriesCollection(i)

The object browser shows Border is a property of SeriesLines which is a
property of ChartGroup. the help system says:

With Charts("Chart1").ChartGroups(1)
.HasSeriesLines = True
With .SeriesLines.Border
.LineStyle = xlThin
.Weight = xlMedium
.ColorIndex = 3
End With
End With

I was able to change the series line formatting with
SeriesCollection(i).Border

Arne



All times are GMT +1. The time now is 05:11 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com