How can I delete multiple sheets in VBA...

G

Guest

Greetings All,

How can I delete multiple sheets in VBA without having to acknowledge the
Excel warning message for each sheet?

I wrote a VBA routine that would loop through and delete all but the first
sheet.
But I have to acknowledge the warning message for each shett.

Is there a way to select a range of sheets for deletion and only have to
acknowledge the deletion once OR can I supress the warning message?

Thanks in advance!!!
 
G

Guest

Not sure exactly what you rcode looks like but this will work...

Sub DeleteSheets
dim wks as worksheet
on error goto Errorhandler
application.displayalerts = false

for each wks in worksheets
if wks.name <> "Main" then wks.delete
next wks

Errorhandler:
application.displayalerts = true
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