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

I am trying to figure out what sort of code I can use in my vba that
would allow it to recognize whether a worksheet with a particular name
exists or not. I would like to use it in conjunction with an if-then
so that it will do one thing or another dependent on the presence (or
lack of) this sheet.

TIA

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Does a worksheet exist?

Use this function


'-----------------------------------------------------------------
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


--

HTH

RP
(remove nothere from the email address if mailing direct)


"papa jonah" wrote in message
oups.com...
I am trying to figure out what sort of code I can use in my vba that
would allow it to recognize whether a worksheet with a particular name
exists or not. I would like to use it in conjunction with an if-then
so that it will do one thing or another dependent on the presence (or
lack of) this sheet.

TIA



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default Does a worksheet exist?

Here is a function...

Public Function SheetExists(SName As String, _
Optional ByVal WB As Workbook) As Boolean
'Chip Pearson
On Error Resume Next
If WB Is Nothing Then Set WB = ThisWorkbook
SheetExists = CBool(Len(WB.Sheets(SName).Name))
End Function
--
HTH...

Jim Thomlinson


"papa jonah" wrote:

I am trying to figure out what sort of code I can use in my vba that
would allow it to recognize whether a worksheet with a particular name
exists or not. I would like to use it in conjunction with an if-then
so that it will do one thing or another dependent on the presence (or
lack of) this sheet.

TIA


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
Does worksheet exist BB Ivan Excel Discussion (Misc queries) 1 January 29th 09 10:04 PM
Does Worksheet Exist BillCPA Excel Discussion (Misc queries) 5 April 19th 05 11:22 PM
Does a worksheet exist Kaval[_2_] Excel Programming 3 May 31st 04 07:21 AM
Does worksheet exist Robert S Excel Programming 3 May 18th 04 07:59 PM
check if a worksheet exist - VBA Warren Excel Programming 1 September 10th 03 05:02 AM


All times are GMT +1. The time now is 01:37 AM.

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

About Us

"It's about Microsoft Excel"