Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Testing to see if a sheet name exists

I have a procedure that adds a sheet and then names the sheet from a
list. Then it will add another sheet and name the next sheet from the
next name in the list.

My problem is that, on occassion, a name will be duplicated. I need
the information associated with the both the duplicated names but you
can't name 2 sheets with the same name.

I don't know how to test for the existence of the name in the
workbook. If I did - I could use an if statement to say that if there
is a sheet with the same name then add a 1 or a space to distinguish
the second sheet.

I've tried on error goto line1: - but this doesn't seem to work.

Can anybody help me?

Thanks much in advance
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Testing to see if a sheet name exists

Here is one I use in a menu program from a sheet name typed into a cell.
The key for you is
If Sheets(ActiveCell.Value) Is Nothing Then


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Application.DisplayAlerts = False
Dim WantedSheet As String
WantedSheet = Trim(ActiveCell.Value)
If WantedSheet = "" Then Exit Sub
On Error Resume Next
If Sheets(ActiveCell.Value) Is Nothing Then
GetWorkbook ' calls another macro to do that
Else
Sheets(ActiveCell.Value).Select
ActiveSheet.Range("a4").Select
End If
Application.DisplayAlerts = True
End Sub
"anita" wrote in message
m...
I have a procedure that adds a sheet and then names the sheet from a
list. Then it will add another sheet and name the next sheet from the
next name in the list.

My problem is that, on occassion, a name will be duplicated. I need
the information associated with the both the duplicated names but you
can't name 2 sheets with the same name.

I don't know how to test for the existence of the name in the
workbook. If I did - I could use an if statement to say that if there
is a sheet with the same name then add a 1 or a space to distinguish
the second sheet.

I've tried on error goto line1: - but this doesn't seem to work.

Can anybody help me?

Thanks much 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
check if sheet exists mohavv Excel Discussion (Misc queries) 1 November 21st 07 01:58 AM
Checking if Sheet Exists? [email protected] Excel Discussion (Misc queries) 5 September 1st 06 03:27 PM
check if the sheet/tag exists Alex Excel Worksheet Functions 2 March 14th 06 08:58 PM
Sheet name already exists eddie_zoom Excel Discussion (Misc queries) 1 March 11th 05 02:53 PM
check if sheet exists Ross[_6_] Excel Programming 3 July 25th 03 06:46 PM


All times are GMT +1. The time now is 10:07 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"