+ Reply to Thread
Results 1 to 3 of 3

worksheet exists or not

  1. #1
    Registered User
    Join Date
    05-04-2006
    Posts
    3

    worksheet exists or not

    How do I check if a worksheet exists or not before accessing it.

  2. #2
    Jim Thomlinson
    Guest

    RE: worksheet exists or not

    This function will let you know if a sheet exists...

    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

    Use it like...

    if sheetexists("Sheet1") then sheets("Sheet1").Select
    --
    HTH...

    Jim Thomlinson


    "skvabbili" wrote:

    >
    > How do I check if a worksheet exists or not before accessing it.
    >
    >
    > --
    > skvabbili
    > ------------------------------------------------------------------------
    > skvabbili's Profile: http://www.excelforum.com/member.php...o&userid=34135
    > View this thread: http://www.excelforum.com/showthread...hreadid=539068
    >
    >


  3. #3
    Bob Phillips
    Guest

    Re: worksheet exists or not

    If SheetExists(sheetname) Then
    '


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

    Bob Phillips

    (remove xxx from email address if mailing direct)

    "skvabbili" <[email protected]> wrote in
    message news:[email protected]...
    >
    > How do I check if a worksheet exists or not before accessing it.
    >
    >
    > --
    > skvabbili
    > ------------------------------------------------------------------------
    > skvabbili's Profile:

    http://www.excelforum.com/member.php...o&userid=34135
    > View this thread: http://www.excelforum.com/showthread...hreadid=539068
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1