The first code needs the user to select a chart to start the routine.
If no chart is selected, a message box appears:
MsgBox "No chart selected. Please select a chart."
The second code needs the user to enter the chart name in the code.
How do you modify the second code to work like the first one?
Code 1:
Sub color001()
If ActiveChart Is Nothing Then
MsgBox "No chart selected. Please select a chart."
Else
Dim rPatterns As Range
Dim iCategory As Long
Dim vCategories As Variant
Dim rCategory As Range
On Error Resume Next
Set rPatterns = Application.InputBox(Title:="Select Color Range", Prompt:="", Type:=8)
With ActiveChart.SeriesCollection(1)
vCategories = .XValues
For iCategory = 1 To UBound(vCategories)
Set rCategory = rPatterns.Find(What:=vCategories(iCategory))
.Points(iCategory).Format.Fill.ForeColor.RGB = rCategory.Interior.color
.Points(iCategory).Format.Line.ForeColor.RGB = rCategory.Borders.color
.Points(iCategory).Format.Line.Weight = 1
.Points(iCategory).Format.Shadow.Visible = msoFalse
Next
End With
On Error GoTo 0
End If
Code 2:
Sub removeZeroLabels001()
' If ActiveChart Is Nothing Then
' MsgBox "No chart selected. Please select a chart."
' Else
Dim cht As Chart
Dim chtObj As ChartObject
Set chtObj = ActiveSheet.ChartObjects("Chart A") 'SET
Set cht = chtObj.Chart
Dim ser As Series
For Each ser In cht.SeriesCollection
Dim vals As Variant
vals = ser.Values
Dim i As Integer
For i = LBound(vals) To UBound(vals)
If vals(i) = 0 Then
With ser.Points(i)
If .HasDataLabel Then
.DataLabel.Delete
End If
End With
End If
Next i
Next ser
End Sub