PDA

View Full Version : Check if Myinput = to sheetnames



Djblois
09-19-2006, 03:39 AM
I have users input the name for a new sheet but sometimes they give it the same name as a sheet already in the file, so I created this code but it doesn't seem to work.


For nameTest = 1 To Worksheets.Count
On Error Resume Next
If Worksheets(nameTest).Name = (myInput) Then
MsgBox "You can not give two reports the same name. Please choose another name!"
PivotTableOptions.Show
End
End If
Next

Bob Phillips
09-19-2006, 03:45 AM
If SheetExists(MyInput) Then
MsgBox "You can not give two reports the same name. Please choose another name!"
PivotTableOptions.Show
End

'-----------------------------------------------------------------
Function SheetExists(Sh As String, _
Optional wb As Workbook) As Boolean
'-----------------------------------------------------------------
Dim oWs As Worksheet
If wb Is Nothing Then Set wb = ActiveWorkbook
On Error Resume Next
SheetExists = CBool(Not wb.Worksheets(Sh) Is Nothing)
On Error GoTo 0
End Function