Deleting Worksheets

E

El Bee

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.
 
D

Don Guillett

Sub test()
Application.DisplayAlerts = False
For Each wks In Worksheets
if wks.name<>"Profiles" then ws.delete
Next wks
Application.DisplayAlerts = true
end sub
 
J

JLGWhiz

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top