Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2006

Tip: Looking for answers? Try searching our database.

Deleting all sheets except one

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nirmal Singh - 26 Jan 2006 15:50 GMT
I have a workbook in which I need to delete all sheets except one
called "SummaryReport".  I have tried using the following code

For z = 1 To xlBook.Worksheets.Count
       If xlBook.Worksheets(z).Name <> "SummaryReport" Then
xlBook.Worksheets(z).Delete
   Next z

This is falling over (I presume because the count changes as sheets
are deleted).  How can I do this?

Nirmal
Ron de Bruin - 26 Jan 2006 15:57 GMT
You can use this

For Each sh In ThisWorkbook.Worksheets

If sh.Name <> "SummaryReport" Then

Signature

Regards Ron de Bruin
http://www.rondebruin.nl

>I have a workbook in which I need to delete all sheets except one
> called "SummaryReport".  I have tried using the following code
[quoted text clipped - 8 lines]
>
> Nirmal
Nirmal Singh - 26 Jan 2006 16:01 GMT
>I have a workbook in which I need to delete all sheets except one
>called "SummaryReport".  I have tried using the following code
[quoted text clipped - 8 lines]
>
>Nirmal

I have changed the loop

for z=xlBook.Worksheets.count to 1 step -1

It works now.

Nirmal
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.