ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Checking if a worksheet already exists... (https://www.excelbanter.com/excel-programming/304105-checking-if-worksheet-already-exists.html)

JR[_5_]

Checking if a worksheet already exists...
 
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

Frank Kabel

Checking if a worksheet already exists...
 
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


--
Regards
Frank Kabel
Frankfurt, Germany


JR wrote:
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



All times are GMT +1. The time now is 10:31 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com