Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Search and Delete

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Search and Delete

Tom

You the man on this stuff. Fixed it on the first try!

Thank you greatly!
Ben H.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
keyword search and delete row mikeyVo Excel Discussion (Misc queries) 2 August 1st 06 05:32 PM
SEARCH AND DELETE Sean[_15_] Excel Programming 12 May 24th 06 04:21 PM
Need help: search and delete columns [email protected] Excel Programming 2 May 18th 06 09:40 PM
Add-in to search and delete Robert Christie[_3_] Excel Programming 1 October 21st 04 05:49 PM
Search and Delete scottnshelly[_56_] Excel Programming 0 July 4th 04 03:33 AM


All times are GMT +1. The time now is 05:10 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"