View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Deleting a sheet if it exists?

Just a word of warning. If sheet4 doesn't exist, then the .delete will fail and
none of those worksheets will be deleted.

I think I'd just use:

Sub deletesheets()
Application.DisplayAlerts = False
On Error Resume Next
sheets("sheet1").delete
sheets("sheet2").delete
sheets("sheetetc").delete
on error goto 0
application.displayalerts = true
End Sub

ps. to the OP: remember that there has to be at least one visible sheet when
you're done.

Don Guillett wrote:

try

Sub deletesheets()
Application.DisplayAlerts = False
On Error Resume Next
myarray = Array("sheet1", "sheet4", "sheetetc")
Sheets(myarray).Delete
End Sub

--
Don Guillett
SalesAid Software

"drucey" wrote in
message ...

Me again!

Flying along nicely, apart from...

In a macro i have:

Sheets("Completed Orders").Delete
Sheets("Partially Arrived Orders").Delete
Sheets("Draft Orders").Delete
Sheets("Placed Orders").Delete

But coming from another macro that's already deleted them (in some
cases only)..

How would i say

IF sheet "completed orders" exists then delete else not to worry

Thanks all


--
drucey
------------------------------------------------------------------------
drucey's Profile:
http://www.excelforum.com/member.php...o&userid=32553
View this thread: http://www.excelforum.com/showthread...hreadid=523544


--

Dave Peterson