I am running Excel 2007 and Windows XP Professional. I had multiple charts in a worksheet and needed some as chart objects, each in their own tab, so I copied them to chart tabs. I then deleted the originals from the worksheet. I have some code that updates the charts in the worksheet but when I run this (what is below; this is not the actual code that does the updates, which works fine until it gets to a 'ghost' chart) to give me the names and positions of the charts:
Dim int_ChartCounter As Integer, str_ChartName As String
For int_ChartCounter = 1 To ActiveSheet.ChartObjects.Count
str_ChartName = ActiveSheet.ChartObjects(int_ChartCounter).Name & " - " & ActiveSheet.ChartObjects(int_ChartCounter).TopLeftCell.Address
Debug.Print str_ChartName
Next
it lists all the ones that are still there and the deleted ones like this:
Chart 255 - $R$392
Chart 256 - $R$392
Chart 257 - $R$392
Chart 258 - $U$399
None of them were called Chart 255 etc, they had meaningful names which have been replaced with Chart... When I look at the cell location (e.g. R392) there is nothing there. If I add:
If Left(str_ChartName, 5) = "Chart" Then
ActiveSheet.ChartObjects(int_ChartCounter).Activate
ActiveChart.Parent.Delete
End If
I get an application defined or object defined error.
I realize that I could modify my actual code with:
If Left(str_ChartName, 5) = "Chart" Then
don't run rest of code
Else
run rest of code
End If
but I fear this may lead to problems later. Any ideas?
Dim int_ChartCounter As Integer, str_ChartName As String
For int_ChartCounter = 1 To ActiveSheet.ChartObjects.Count
str_ChartName = ActiveSheet.ChartObjects(int_ChartCounter).Name & " - " & ActiveSheet.ChartObjects(int_ChartCounter).TopLeftCell.Address
Debug.Print str_ChartName
Next
it lists all the ones that are still there and the deleted ones like this:
Chart 255 - $R$392
Chart 256 - $R$392
Chart 257 - $R$392
Chart 258 - $U$399
None of them were called Chart 255 etc, they had meaningful names which have been replaced with Chart... When I look at the cell location (e.g. R392) there is nothing there. If I add:
If Left(str_ChartName, 5) = "Chart" Then
ActiveSheet.ChartObjects(int_ChartCounter).Activate
ActiveChart.Parent.Delete
End If
I get an application defined or object defined error.
I realize that I could modify my actual code with:
If Left(str_ChartName, 5) = "Chart" Then
don't run rest of code
Else
run rest of code
End If
but I fear this may lead to problems later. Any ideas?