Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Deleting a sheet if it exists?


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 som
cases only)..

How would i say

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

Thanks al

--
druce
-----------------------------------------------------------------------
drucey's Profile: http://www.excelforum.com/member.php...fo&userid=3255
View this thread: http://www.excelforum.com/showthread.php?threadid=52354

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Deleting a sheet if it exists?

drucey wrote:
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


By wrapping the code in an error trapping block, for instance

Sub DeleteIfExists(ByVal SheetName as String)
On Error Resume Next
Sheets(SheetName).Delete
Err.Clear
End Sub
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Deleting a sheet if it exists?


my god! i love this place!

thank you so much :

--
druce
-----------------------------------------------------------------------
drucey's Profile: http://www.excelforum.com/member.php...fo&userid=3255
View this thread: http://www.excelforum.com/showthread.php?threadid=52354

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Deleting a sheet if it exists?

glad to help

--
Don Guillett
SalesAid Software

"drucey" wrote in
message ...

my god! i love this place!

thank you so much :)


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





  #6   Report Post  
Posted to microsoft.public.excel.programming
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
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
Sheet name already exists eddie_zoom Excel Discussion (Misc queries) 1 March 11th 05 02:53 PM
Sheet Exists in another file? Utkarsh[_2_] Excel Programming 1 November 2nd 04 01:57 AM
Rename sheet if exists Phil Floyd Excel Programming 6 April 5th 04 06:58 PM
How can I know if a sheet exists ? Ben.C Excel Programming 3 December 29th 03 09:36 AM
Testing to see if a sheet name exists anita Excel Programming 1 September 4th 03 10:14 PM


All times are GMT +1. The time now is 09:43 PM.

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"