PC Review


Reply
Thread Tools Rate Thread

Delete sheets - all except 3

 
 
joecrabtree
Guest
Posts: n/a
 
      19th Dec 2006
To all,

I have a workbook with many sheets, and wish to delete all of them
apart from the following 3:

WELCOME, ImportedRawData, + ImportedDataEdit


How can I do this?

Thanks very much for your help in advance,

Regards

Joseph Crabtree

 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      19th Dec 2006
Dim ws As Worksheet
Application.DisplayAlerts = False
For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> "WELCOME" And _
ws.Name <> "ImportedRawData" And _
ws.Name <> "ImportedDataEdit" Then
ws.DisplayPageBreaks
End If
Next ws
Application.DisplaAlerts = True

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"joecrabtree" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> To all,
>
> I have a workbook with many sheets, and wish to delete all of them
> apart from the following 3:
>
> WELCOME, ImportedRawData, + ImportedDataEdit
>
>
> How can I do this?
>
> Thanks very much for your help in advance,
>
> Regards
>
> Joseph Crabtree
>



 
Reply With Quote
 
ankur
Guest
Posts: n/a
 
      19th Dec 2006


Hi Joseph,

Try this...

sub test()

dim sheet as object

for each sheet in activeworkbook.sheets

if sheet.name<>"WELCOME" and sheet.name<>"ImportedRawData" and
sheet.name<>"ImportedDataEdit" then

sheet.delete

end if

next sheet
End sub

Regards
Ankur
www.xlmacros.com


On Dec 19, 2:46 pm, "joecrabtree" <thejoecrabt...@gmail.com> wrote:
> To all,
>
> I have a workbook with many sheets, and wish to delete all of them
> apart from the following 3:
>
> WELCOME, ImportedRawData, + ImportedDataEdit
>
> How can I do this?
>
> Thanks very much for your help in advance,
>
> Regards
>
> Joseph Crabtree


 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      19th Dec 2006
One more...

Dim wks As Worksheet
Application.DisplayAlerts = False
For Each wks In ActiveWorkbook.Worksheets
select case lcase(wks.name)
case is = "welcome", "importedrawdata","importeddataedit"
'do nothing
case else
wks.delete
end select
next wks
Application.DisplaAlerts = True

Since the "select case" is looking for lower case characters (lcase), make sure
you type those strings in lower case.



joecrabtree wrote:
>
> To all,
>
> I have a workbook with many sheets, and wish to delete all of them
> apart from the following 3:
>
> WELCOME, ImportedRawData, + ImportedDataEdit
>
> How can I do this?
>
> Thanks very much for your help in advance,
>
> Regards
>
> Joseph Crabtree


--

Dave Peterson
 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      19th Dec 2006
Autocomplete is too quick!

ws.displaypagebreaks
should be
ws.delete

<vbg>

Bob Phillips wrote:
>
> Dim ws As Worksheet
> Application.DisplayAlerts = False
> For Each ws In ActiveWorkbook.Worksheets
> If ws.Name <> "WELCOME" And _
> ws.Name <> "ImportedRawData" And _
> ws.Name <> "ImportedDataEdit" Then
> ws.DisplayPageBreaks
> End If
> Next ws
> Application.DisplaAlerts = True
>
> --
> ---
> HTH
>
> Bob
>
> (change the xxxx to gmail if mailing direct)
>
> "joecrabtree" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > To all,
> >
> > I have a workbook with many sheets, and wish to delete all of them
> > apart from the following 3:
> >
> > WELCOME, ImportedRawData, + ImportedDataEdit
> >
> >
> > How can I do this?
> >
> > Thanks very much for your help in advance,
> >
> > Regards
> >
> > Joseph Crabtree
> >


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
sub to delete all sheets other than x, y, z Max Microsoft Excel Programming 6 2nd Jan 2008 01:04 AM
Delete Sheets Andibevan Microsoft Excel Programming 3 24th Jun 2005 12:17 AM
Re: Macro to delete sheets and saves remaining file does not properly delete module gazornenplat Microsoft Excel Programming 0 22nd Jun 2005 01:12 AM
Macro to delete sheets and saves remaining file does not properly delete module pherrero Microsoft Excel Programming 7 21st Jun 2005 05:16 PM
delete all sheets except... caroline Microsoft Excel Programming 4 22nd May 2004 04:29 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:15 PM.