Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default 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   Report Post  
Posted to microsoft.public.excel.programming
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Naming new worksheets paz24 Excel Discussion (Misc queries) 0 February 1st 06 11:46 AM
Naming worksheets... tojo107 Excel Discussion (Misc queries) 3 April 7th 05 07:29 PM
naming worksheets Shooter Excel Worksheet Functions 1 December 3rd 04 04:09 PM
Naming Worksheets in VBE Don Guillett[_4_] Excel Programming 0 July 18th 03 08:17 PM
Naming Worksheets in VBE Chip Pearson Excel Programming 0 July 18th 03 08:16 PM


All times are GMT +1. The time now is 05:04 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"