Does sheet exist?

  • Thread starter Thread starter Sean Evanovich
  • Start date Start date
S

Sean Evanovich

What's the proper way to check and see if a specific
sheet exits in the workbook?

I need to pull data from this sheet IF it exists...and if
it doesn't exist I need to pull data from another sheet I
know will be there...

If "Multi-Acct Summary" exists then
GetDataFromMultiAccount
Else
GetDataFromSingleAccount
End if

Thanks!!!
 
Sean,

Use a function like

Function SheetExists(SheetName As String) As Boolean
On Error Resume Next
SheetExists = CBool(Len(ThisWorkbook.Worksheets(SheetName).Name))
End Function


Then, you can call this with code like

If SheetExists("Sheet1") = True Then
' do something
Else
' do something else
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Try this. If sheet 22 does not exist it gets info from sheet 2.

Sub getifthere()
On Error Resume Next
MsgBox Sheets("Sheet22").Range("c5")
MsgBox Sheets("Sheet2").Range("c5")
End Sub
 

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

Back
Top