Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Does sheet exist?

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!!!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Does sheet exist?

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


"Sean Evanovich" wrote in message
...
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!!!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Does sheet exist?

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

--
Don Guillett
SalesAid Software

"Sean Evanovich" wrote in message
...
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!!!



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Want a trace a same values exist in two different sheet Mukesh Excel Worksheet Functions 2 April 23rd 09 12:56 PM
verify if spesific sheet exist Miri Excel Discussion (Misc queries) 3 February 26th 07 01:04 PM
VBA: Make a new sheet if it doesn't exist PaulW Excel Discussion (Misc queries) 2 May 8th 06 03:45 PM
VBA, Make a new sheet if it doesn't exist PaulW Excel Discussion (Misc queries) 1 May 5th 06 05:25 PM
Am I Looking For Something That Doesn't Exist? seanryann Excel Discussion (Misc queries) 11 April 1st 06 06:10 PM


All times are GMT +1. The time now is 08:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"