Delete Multiple sheets

M

moglione1

Hi all,

I have a macro that creates upto about 15 sheets of pivot tables and
then copies the data onto other sheets. I would like to know how I can
delete all of these sheets as they are not needed.

These sheets all have the standard new sheet name. I.e. Sheetxx

The VBA Code for this would be tremendous :)
 
G

Guest

This should do the trick. Put it in a standard module...

Sub DeleteSheets()
Dim wks As Worksheet
On Error GoTo ErrorHandler
Application.DisplayAlerts = False
For Each wks In Worksheets
If Left(wks.Name, 5) = "Sheet" Then wks.Delete
Next wks
ErrorHandler:
Application.DisplayAlerts = False
End Sub
 
G

Guest

Try this:

After your done with the data on each sheet, before you create the next
sheet use ActiveSheet.Delete if it's the active sheet; -use your object
variable for the sheet if it's not!

Regards, GS
 
G

Guest

Hi Jim,

You should be turning .DisplayAlerts back on (TRUE) in your ErrorHandler:
Regards, GS
 

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

Top