Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default checking for duplicate worksheets

I have written a little VBA to create a new worksheet tab. The naming of
this tab is obtained from a specific cell. If a worksheet name already
matches data that is entered into that cell, an error occurs. How do I first
check if the worksheet name does not already exist before trying to rename
the new sheet?

Sheets("Template").Select
Sheets("Template").Copy After:=Sheets(2)
Sheets("Template (2)").Select
ActiveSheet.Name = Sheets("StartHere").Range("B3")

Thanks in advance,

Rick


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default checking for duplicate worksheets

Hi Rick

You can trap the error like this

On Error Resume Next
ActiveSheet.Name = Sheets("StartHere").Range("B3")
On Error GoTo 0

Or use a function to check if the sheet exist

Function SheetExists(SName As String, _
Optional ByVal WB As Workbook) As Boolean
'Chip Pearson
On Error Resume Next
If WB Is Nothing Then Set WB = ThisWorkbook
SheetExists = CBool(Len(WB.Sheets(SName).Name))
End Function

You can use this line then

If SheetExists("test") = True Then


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Rick B" wrote in message ...
I have written a little VBA to create a new worksheet tab. The naming of
this tab is obtained from a specific cell. If a worksheet name already
matches data that is entered into that cell, an error occurs. How do I first
check if the worksheet name does not already exist before trying to rename
the new sheet?

Sheets("Template").Select
Sheets("Template").Copy After:=Sheets(2)
Sheets("Template (2)").Select
ActiveSheet.Name = Sheets("StartHere").Range("B3")

Thanks in advance,

Rick




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
Formula for checking duplicate numbers Ron[_5_] Excel Discussion (Misc queries) 3 March 13th 10 03:55 PM
Macro for checking duplicate entries Ken[_2_] Excel Worksheet Functions 6 October 8th 07 12:17 PM
Checking for duplicate entries Daniel- Sydney Excel Discussion (Misc queries) 3 November 7th 06 09:16 AM
Checking for duplicate entries over multiple worksheets madbloke Excel Discussion (Misc queries) 2 May 11th 06 12:56 PM
Checking for duplicate records / rows Hru48 Excel Discussion (Misc queries) 2 February 26th 06 11:12 PM


All times are GMT +1. The time now is 06:55 AM.

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

About Us

"It's about Microsoft Excel"