Checking if a worksheet already exists...

  • Thread starter Thread starter JR
  • Start date Start date
J

JR

I want to check if a worksheet already exists based on its tab name
(for example, "Test"). If it exists, I want to delete it, then add a
blank worksheet with the same name. Is there a simple way of doing
this?

Thanks!
JR
 
Hi
you may try something like the following

sub foo()
dim wks as worksheet
on error resume next
set wks = activeworkbook.worksheets("Test")
on error goto 0
if not wks is nothing then
application.displayalerts=false
wks.delete
application.displayalerts=True
end if
'insert your new sheet
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

Back
Top