On Close Macro - stop warning message

  • Thread starter Thread starter M Shannon
  • Start date Start date
M

M Shannon

I have this macro on close:

Sheets("Bakery").Select
ActiveWindow.SelectedSheets.Delete

I need to do two things.

1) If the sheet doesn't exist I want the macro to do
nothing and carry on to delete the next worksheet.

2) If the sheet does exist I want the macro to delete it
without the warning.

Any help is much appreciated.
Many thanks
 
You can avoid the error by:

on error resume next
sheets("bakery").delete
on error goto 0

(But what does Next mean if that worksheet doesn't exist?)

And to hide the warning message:

application.displayalerts = false
on error resume next
sheets("bakery").delete
on error goto 0
application.displayalerts = true

and you can delete as many sheets as you want in that little bit of code:

application.displayalerts = false
on error resume next
sheets("bakery").delete
sheets("butcher").delete
sheets("candlestickmaker").delete
 
On Error Resume Next
Application.Displayalerts = False
Sheets("Bakery").Delete
Applicaton.displayAlerts = True
On Error goto 0
 

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

Back
Top