The VBA code below formats the interior colours of a Pie Chart based on entries (1, 2 or 3) in a format column (G15:G29).
What I can't work out is how to start the macro from any initially selected cell in column G (variable starting point) and then exit the macro when it hits the first blank cell.
Can anyone help? Thanks.
What I can't work out is how to start the macro from any initially selected cell in column G (variable starting point) and then exit the macro when it hits the first blank cell.
Can anyone help? Thanks.
VBA Code:
Sub FormatChartFillAndFont()
Dim I As Long
Dim FormatCol As Range
Set FormatCol = Range("G15:G29")
With ActiveSheet.ChartObjects("PieChart1").Chart.SeriesCollection(1)
For I = 1 To 15
Select Case FormatCol.Cells(I, 1).Value
Case Is = 1
.Points(I).Interior.Color = RGB(255, 255, 255)
.Points(I).Format.Line.Visible = msoFalse
.DataLabels.Font.Size = 10
.Points(I).DataLabel.Font.Color = vbWhite
Case Is = 2
.Points(I).Interior.Color = RGB(0, 102, 0)
.Points(I).Format.Line.Visible = msoTrue
.DataLabels.Font.Size = 10
.Points(I).DataLabel.Font.Color = vbWhite
Case Is = 3
.Points(I).Interior.Color = RGB(0, 153, 0)
.Points(I).Format.Line.Visible = msoTrue
.DataLabels.Font.Size = 10
.Points(I).DataLabel.Font.Color = vbWhite
End Select
Next I
End With
End Sub