T
Terry Detrie
I have a chart with 9 series, and macro that will make them hidden or
visible, depending on the contents of a range of 9 cells in a
worksheet ("IR-Graph")
An odd thing happens sometimes with the the 9th series. I get an run
time error 1004 (Unable to get property of LegendEntry class).
Through a lot of trial and error, I found that this error only occurs
with the 3rd series is turned 'on'.
Since both cases in the IF...THEN block have multiple actions on the
LegendEntries, I turned off Series #3 and stepped through the code.
After first line clears (either case) I know Series #9 exists and
there's no error. Then I turn Series #3 off, which *shouldn't* affect
Series#9. When I step into next line of code I get the error. When I
turn Series #3 back off, I'm able to advance to next line of code
again.
I'm usually pretty good at debugging but this is too weird. Help!
Sub Graph_Legend(oCht As Chart)
Dim Counter As Integer
Application.ScreenUpdating = False
With oCht
For Counter = 1 To 9
If Sheets("IR-Graph").Cells(Counter + 2, 1).Value = 0 Then
' Turn graph line off
.Legend.LegendEntries(Counter).LegendKey.Border.LineStyle =
xlNone
.Legend.LegendEntries(Counter).Font.ColorIndex = 2
Else
' Turn graph line on
.Legend.LegendEntries(Counter).Font.ColorIndex = xlAutomatic
.Legend.LegendEntries(Counter).LegendKey.Border.ColorIndex =
xlAutomatic
.Legend.LegendEntries(Counter).LegendKey.Border.Weight =
xlMedium
End If
Next Counter
End With
Application.ScreenUpdating = True
End Sub
Terry Detrie
visible, depending on the contents of a range of 9 cells in a
worksheet ("IR-Graph")
An odd thing happens sometimes with the the 9th series. I get an run
time error 1004 (Unable to get property of LegendEntry class).
Through a lot of trial and error, I found that this error only occurs
with the 3rd series is turned 'on'.
Since both cases in the IF...THEN block have multiple actions on the
LegendEntries, I turned off Series #3 and stepped through the code.
After first line clears (either case) I know Series #9 exists and
there's no error. Then I turn Series #3 off, which *shouldn't* affect
Series#9. When I step into next line of code I get the error. When I
turn Series #3 back off, I'm able to advance to next line of code
again.
I'm usually pretty good at debugging but this is too weird. Help!
Sub Graph_Legend(oCht As Chart)
Dim Counter As Integer
Application.ScreenUpdating = False
With oCht
For Counter = 1 To 9
If Sheets("IR-Graph").Cells(Counter + 2, 1).Value = 0 Then
' Turn graph line off
.Legend.LegendEntries(Counter).LegendKey.Border.LineStyle =
xlNone
.Legend.LegendEntries(Counter).Font.ColorIndex = 2
Else
' Turn graph line on
.Legend.LegendEntries(Counter).Font.ColorIndex = xlAutomatic
.Legend.LegendEntries(Counter).LegendKey.Border.ColorIndex =
xlAutomatic
.Legend.LegendEntries(Counter).LegendKey.Border.Weight =
xlMedium
End If
Next Counter
End With
Application.ScreenUpdating = True
End Sub
Terry Detrie