Search and Delete
Dim wSheet as Chart
Dim ch as Chart
Dim strSurfPlotName as String
strSurfPlotName = "MyChart"
On Error Resume Next
Set wSheet = Sheets(strSurfPlotName)
On Error goto 0
If wSheet Is Nothing Then 'Doesn't exist
for each ch in Activeworkbook.Charts
if instr(1,ch.name, strSurfPlotName,vbTextCompare) then
ans = msgbox( ch.Name & " appears a close match" _
vbNewLine & "Delete?", vbYesNo)
if ans = vbYes then
Application.DisplayAlerts = False
ch.Delete
Application.DisplayAlerts = True
end if
end if
Next ch
Else 'Does exist
Application.DisplayAlerts = False
Charts(strSurfPlotName).Delete
Application.DisplayAlerts = True
Set wSheet = Nothing
End If
--
Regards,
Tom Ogilvy
"Ben H" wrote:
Hi all
I need to search through a wookbook for a chart and then if it is there,
delete it. Any ideas as to how to do this? I have tried this but it doesn't
work right.
Set wSheet = Sheets(strSurfPlotName)
If wSheet Is Nothing Then 'Doesn't exist
Set wSheet = Nothing
On Error GoTo 0
Else 'Does exist
Application.DisplayAlerts = False
Charts(strSurfPlotName).Delete
Application.DisplayAlerts = True
Set wSheet = Nothing
On Error GoTo 0
End If
it doesn't search right.
Thanks - Ben H
|