Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Naming Worksheets
I have a macro that creates and names a worksheet each time it is run.
However, if you have already run the macro and have not deleted the worksheet before running the macro again, the macro returns an error - Cannot rename a sheet to the same name as another sheet. What is the best way to handle this error? Thanks in advance |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Naming Worksheets
Dim sh as Worksheet
On Error Resume Next set sh = worksheets("Name1") On Error goto 0 if not sh is nothing then msgbox "Sheet with the name of Name1 already exists" else Worksheets.Add.Name = "Name1" set sh = Worksheets("Name1") End if ' now sh holds a reference to the sheet Name1 -- Regards, Tom Ogilvy "Chaz" wrote in message ... I have a macro that creates and names a worksheet each time it is run. However, if you have already run the macro and have not deleted the worksheet before running the macro again, the macro returns an error - Cannot rename a sheet to the same name as another sheet. What is the best way to handle this error? Thanks in advance |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Naming new worksheets | Excel Discussion (Misc queries) | |||
Naming worksheets... | Excel Discussion (Misc queries) | |||
naming worksheets | Excel Worksheet Functions | |||
Naming Worksheets in VBE | Excel Programming | |||
Naming Worksheets in VBE | Excel Programming |