PC Review


Reply
Thread Tools Rate Thread

Deleting Worksheets

 
 
El Bee
Guest
Posts: n/a
 
      6th Feb 2008
I have a workbook that contains 4 worksheets:
EcomSec, Programs, EcomData, & Profiles.

I do a lot of data manipulation between the EcomSec & EcomData ws and paste
that data into the Profiles ws.
After this completes I want to delete all but the Profiles ws. It was
working until one of the worksheets was moved.

Here's the code.
Sub test()
Application.DisplayAlerts = False
For Each wks In Worksheets
If InStr("Programs", wks.Name) > 0 Then wks.Delete
If InStr("EcomSec", wks.Name) > 0 Then wks.Delete
If InStr("EcomData", wks.Name) > 0 Then wks.Delete
Next wks

End Sub

I know there's got to be a way to do this but not sure how.

Thanks for your help.
 
Reply With Quote
 
 
 
 
Don Guillett
Guest
Posts: n/a
 
      6th Feb 2008
Sub test()
Application.DisplayAlerts = False
For Each wks In Worksheets
if wks.name<>"Profiles" then ws.delete
Next wks
Application.DisplayAlerts = true
end sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"El Bee" <(E-Mail Removed)> wrote in message
news:4B4D29D4-EDDF-4C5E-A0A0-(E-Mail Removed)...
>I have a workbook that contains 4 worksheets:
> EcomSec, Programs, EcomData, & Profiles.
>
> I do a lot of data manipulation between the EcomSec & EcomData ws and
> paste
> that data into the Profiles ws.
> After this completes I want to delete all but the Profiles ws. It was
> working until one of the worksheets was moved.
>
> Here's the code.
> Sub test()
> Application.DisplayAlerts = False
> For Each wks In Worksheets
> If InStr("Programs", wks.Name) > 0 Then wks.Delete
> If InStr("EcomSec", wks.Name) > 0 Then wks.Delete
> If InStr("EcomData", wks.Name) > 0 Then wks.Delete
> Next wks
>
> End Sub
>
> I know there's got to be a way to do this but not sure how.
>
> Thanks for your help.


 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      6th Feb 2008
Why not:

Sub test()
Application.DisplayAlerts = False
For Each wks In Worksheets
If wks.Name <> "Profiles" Then
wks.Delete
End If
Next wks

End Sub


"El Bee" wrote:

> I have a workbook that contains 4 worksheets:
> EcomSec, Programs, EcomData, & Profiles.
>
> I do a lot of data manipulation between the EcomSec & EcomData ws and paste
> that data into the Profiles ws.
> After this completes I want to delete all but the Profiles ws. It was
> working until one of the worksheets was moved.
>
> Here's the code.
> Sub test()
> Application.DisplayAlerts = False
> For Each wks In Worksheets
> If InStr("Programs", wks.Name) > 0 Then wks.Delete
> If InStr("EcomSec", wks.Name) > 0 Then wks.Delete
> If InStr("EcomData", wks.Name) > 0 Then wks.Delete
> Next wks
>
> End Sub
>
> I know there's got to be a way to do this but not sure how.
>
> Thanks for your help.

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      6th Feb 2008
typo
wks

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"Don Guillett" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Sub test()
> Application.DisplayAlerts = False
> For Each wks In Worksheets
> if wks.name<>"Profiles" then ws.delete
> Next wks
> Application.DisplayAlerts = true
> end sub
> --
> Don Guillett
> Microsoft MVP Excel
> SalesAid Software
> (E-Mail Removed)
> "El Bee" <(E-Mail Removed)> wrote in message
> news:4B4D29D4-EDDF-4C5E-A0A0-(E-Mail Removed)...
>>I have a workbook that contains 4 worksheets:
>> EcomSec, Programs, EcomData, & Profiles.
>>
>> I do a lot of data manipulation between the EcomSec & EcomData ws and
>> paste
>> that data into the Profiles ws.
>> After this completes I want to delete all but the Profiles ws. It was
>> working until one of the worksheets was moved.
>>
>> Here's the code.
>> Sub test()
>> Application.DisplayAlerts = False
>> For Each wks In Worksheets
>> If InStr("Programs", wks.Name) > 0 Then wks.Delete
>> If InStr("EcomSec", wks.Name) > 0 Then wks.Delete
>> If InStr("EcomData", wks.Name) > 0 Then wks.Delete
>> Next wks
>>
>> End Sub
>>
>> I know there's got to be a way to do this but not sure how.
>>
>> Thanks for your help.

>


 
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
Deleting Worksheets =?Utf-8?B?SmVmZg==?= Microsoft Excel Programming 1 18th Jul 2007 04:55 AM
Re: Deleting Worksheets Chip Pearson Microsoft Excel Programming 0 7th Dec 2006 06:45 PM
Re: Deleting Worksheets paul.robinson@it-tallaght.ie Microsoft Excel Programming 0 7th Dec 2006 06:36 PM
Deleting worksheets Microsoft Excel Misc 8 20th Sep 2004 07:49 PM
Deleting worksheets jacqui Microsoft Excel Programming 9 29th Mar 2004 02:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:08 PM.