View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default 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