detect worksheet

  • Thread starter Thread starter mike allen
  • Start date Start date
M

mike allen

i would like to see if a specific worksheet is in a workbook. something
like:

If issheet("sheetX") Then
'look up stuff on 'sheetX'
Else
'don't look up stuff on 'sheetX'
End If

i realize "issheet" is wrong, but what would be correct? thanks, mike allen
 
Do you mean this Mike

Sub test()
If ActiveSheet.Name = "Sheet1" Then
MsgBox "Sheet1 is the ActiveSheet"
Else
MsgBox "Sheet1 is not the ActiveSheet"
End If
End Sub
 
Take a look at John Walkenbach's SheetExists function:

http://www.j-walk.com/ss/excel/tips/tip54.htm

You could also do it inline:

Dim wkSht As Worksheet
On Error Resume Next
Set wkSht = Worksheets("SheetX")
On Error GoTo 0
If Not wkSht Is Nothing Then
'look up stuff on 'SheetX'
Else
'don't look up stuff on 'SheetX'
End If
 
Back
Top