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


Can you tell me how to write code to delete all worksheets other tha
those with a pre-specified name. eg all sheets other than Sheet1

Thank

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Delete worksheets

Hello Andym,

Sub test()
Application.DisplayAlerts = False
For Each ws In ThisWorkbook.Sheets
If ws.Name < "Sheet1" Then ws.Delete
Next ws
Application.DisplayAlerts = True
End Sub

You can also replace Thisworkbook with ActiveWorkbook or
Workbooks("Book1.xls") depending on what workbook does the sheets you want
to delete are located.

Regards,

Jon-jon

"andym" wrote in message
...

Can you tell me how to write code to delete all worksheets other than
those with a pre-specified name. eg all sheets other than Sheet1

Thanks


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Delete worksheets


Thanks Jon-jon, that's perfec

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Delete worksheets

Glad to help

"andym" wrote in message
...

Thanks Jon-jon, that's perfect


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Delete worksheets


Sorry, one more thing. How can I adapt the code to delete everythin
other than Sheets1 and 2? I have tried
If ws.Name < "Sheet1" Or "Sheet2" Then ws.Delete but this doesn'
work.

Thank

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Delete worksheets

if ws.name = "Sheet1" _
or ws.name = "Sheet2" then
'don't kill it
else
ws.delete
end if

or

if ws.name < "Sheet1" and ws.Name < "Sheet2" then ws.delete





andym wrote:

Sorry, one more thing. How can I adapt the code to delete everything
other than Sheets1 and 2? I have tried
If ws.Name < "Sheet1" Or "Sheet2" Then ws.Delete but this doesn't
work.

Thanks

------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/


--

Dave Peterson

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Delete worksheets


Thank you

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com

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
VBA to delete worksheets Mark_F via OfficeKB.com Excel Discussion (Misc queries) 2 August 27th 09 06:04 PM
Marco to Delete Worksheets CM4@FL Excel Discussion (Misc queries) 2 February 27th 09 07:26 PM
How to delete blank worksheets Keep_It_Simple_Stupid Excel Worksheet Functions 1 January 23rd 08 09:35 AM
Delete All Worksheets Apart From Some With Particular Name Dave Excel Discussion (Misc queries) 1 October 31st 07 01:30 AM
I can't delete my worksheets Dillon Excel Discussion (Misc queries) 1 March 5th 07 06:10 PM


All times are GMT +1. The time now is 09:55 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"