sheet reference in if statement

K

kristing

I was wondering if there was a way to reference a specific sheet whil
writing an if statement in vba for excel. It would be used in an i
statement that would be something like if the sheet exists then g
ahead and run some other functions. Hope someone knows how to do this
 
B

Bernie Deitrick

kristing,

On Error GoTo SheetDoesntExist
Dim myName As String
myName = Worksheets("SheetName").Name
MsgBox "That Sheet Exists"
'Other code

GoTo SheetExists
SheetDoesntExist:
MsgBox "That sheet doesn't exist"
SheetExists:

HTH,
Bernie
MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top