Locating if a Sheet is present in a workbook

  • Thread starter Thread starter Shane
  • Start date Start date
S

Shane

Two Part Question:

I am looking for code that will locate if a sheet by a specific name is in
the workbook, and then delete it if it is. What is the easiest way to do
this? (I am not sure if an "IF" statement is the best way to go or not).

Secondly, is there a way to keep the warning pop-up from occurring when
trying to delete said sheet?

Thanks!
 
for each ws in worksheets
application.displayalerts =false
if ws.name="Bad Name" then ws.delete
application.displayalerts=true
next ws
 
on error resume next
application.displayalerts = false
sheets("Sheet1").Delete
application.displayalerts = true
on error goto 0
 
Thank you so much... works like a charm!!

Don Guillett said:
for each ws in worksheets
application.displayalerts =false
if ws.name="Bad Name" then ws.delete
application.displayalerts=true
next ws

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)


.
 

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