Private Sub Worksheet_activate()
Dim cht As Chart
Dim ser As Series
Dim iSrs As Long, nSrs As Long
Set cht = ActiveSheet.ChartObjects("Chart 4").Chart
With cht
nSrs = .SeriesCollection.Count
Dim srsName As String
For iSrs = 1 To nSrs
srsName = (.SeriesCollection(iSrs).Name)
Select Case iSrs
Case 1
Set ser = cht.SeriesCollection(iSrs)
ser.Format.Line.Visible = msoFalse
ser.Format.Line.Visible = msoTrue
ser.Format.Line.ForeColor.RGB = RGB(255, 0, 0)
ser.DataLabels.Font.Color = RGB(255, 0, 0)
Case 2
Set ser = cht.SeriesCollection(iSrs)
ser.Format.Line.Visible = msoFalse
ser.Format.Line.Visible = msoTrue
ser.Format.Line.ForeColor.RGB = RGB(0, 28, 93)
ser.DataLabels.Font.Color = RGB(0, 28, 93)
Case 3
Set ser = cht.SeriesCollection(iSrs)
ser.Format.Line.Visible = msoFalse
ser.Format.Line.Visible = msoTrue
ser.Format.Line.ForeColor.RGB = RGB(162, 162, 162)
ser.DataLabels.Font.Color = RGB(162, 162, 162)
Case 4
Set ser = cht.SeriesCollection(iSrs)
ser.Format.Line.Visible = msoFalse
ser.Format.Line.Visible = msoTrue
ser.Format.Line.ForeColor.RGB = RGB(255, 191, 0)
ser.DataLabels.Font.Color = RGB(255, 191, 0)
Case 5
Set ser = cht.SeriesCollection(iSrs)
ser.Format.Line.Visible = msoFalse
ser.Format.Line.Visible = msoTrue
ser.Format.Line.ForeColor.RGB = RGB(177, 208, 235)
ser.DataLabels.Font.Color = RGB(177, 208, 235)
Case 6
Set ser = cht.SeriesCollection(iSrs)
ser.Format.Line.Visible = msoFalse
ser.Format.Line.Visible = msoTrue
ser.Format.Line.ForeColor.RGB = RGB(109, 171, 67)
ser.DataLabels.Font.Color = RGB(109, 171, 67)
Case 7
Set ser = cht.SeriesCollection(iSrs)
ser.Format.Line.Visible = msoFalse
ser.Format.Line.Visible = msoTrue
ser.Format.Line.ForeColor.RGB = RGB(212, 17, 167)
ser.DataLabels.Font.Color = RGB(212, 17, 167)
End Select
Next
End With
End Sub
Thursday, 30 December 2021
Excel Macro to color and formatting different series charts and labels
Labels:
Excel,
Excel Macros
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment