Testing to see if a sheet name exists

  • Thread starter Thread starter anita
  • Start date Start date
A

anita

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
 
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
 
Back
Top