+ Reply to Thread
Results 1 to 5 of 5

On Error Goto ignored

  1. #1
    Fred Smith
    Guest

    On Error Goto ignored

    I wanted to determine whether a sheet existed in the active workbook. So I
    used:

    On Error Goto NoPerfSheet
    Sheets("Performance").Select
    On Error Goto 0

    However, Excel always stopped at the Sheets command, with a Subscript out of
    range error.

    I knew there would never be more than two sheets in the workbook, so I got
    it working by using:

    IF Sheets.Count = 1 Goto NoPerfSheet

    However, I'm why the On Error statement was ignored.

    What conditions causes VBE to ignore On Error?

    --
    Thanks,
    Fred
    Please reply to newsgroup, not e-mail




  2. #2
    Robin Hammond
    Guest

    Re: On Error Goto ignored

    Fred,

    something like this

    Function SheetExists(strName As String) As Boolean
    Dim shName As Worksheet
    On Error Resume Next
    Set shName = Sheets(strName)
    On Error GoTo 0
    SheetExists = Not shName Is Nothing
    End Function

    Robin Hammond
    www.enhanceddatasystems.com

    "Fred Smith" <[email protected]> wrote in message
    news:Od%[email protected]...
    >I wanted to determine whether a sheet existed in the active workbook. So I
    >used:
    >
    > On Error Goto NoPerfSheet
    > Sheets("Performance").Select
    > On Error Goto 0
    >
    > However, Excel always stopped at the Sheets command, with a Subscript out
    > of range error.
    >
    > I knew there would never be more than two sheets in the workbook, so I got
    > it working by using:
    >
    > IF Sheets.Count = 1 Goto NoPerfSheet
    >
    > However, I'm why the On Error statement was ignored.
    >
    > What conditions causes VBE to ignore On Error?
    >
    > --
    > Thanks,
    > Fred
    > Please reply to newsgroup, not e-mail
    >
    >
    >




  3. #3
    Fred Smith
    Guest

    Re: On Error Goto ignored

    That's a workaround I hadn't thought of, and I could see using it sometime.
    Buy why was my On Error Goto ignored?

    --
    Regards,
    Fred
    Please reply to newsgroup, not e-mail


    "Robin Hammond" <[email protected]> wrote in message
    news:[email protected]...
    > Fred,
    >
    > something like this
    >
    > Function SheetExists(strName As String) As Boolean
    > Dim shName As Worksheet
    > On Error Resume Next
    > Set shName = Sheets(strName)
    > On Error GoTo 0
    > SheetExists = Not shName Is Nothing
    > End Function
    >
    > Robin Hammond
    > www.enhanceddatasystems.com
    >
    > "Fred Smith" <[email protected]> wrote in message
    > news:Od%[email protected]...
    >>I wanted to determine whether a sheet existed in the active workbook. So I
    >>used:
    >>
    >> On Error Goto NoPerfSheet
    >> Sheets("Performance").Select
    >> On Error Goto 0
    >>
    >> However, Excel always stopped at the Sheets command, with a Subscript out
    >> of range error.
    >>
    >> I knew there would never be more than two sheets in the workbook, so I
    >> got it working by using:
    >>
    >> IF Sheets.Count = 1 Goto NoPerfSheet
    >>
    >> However, I'm why the On Error statement was ignored.
    >>
    >> What conditions causes VBE to ignore On Error?
    >>
    >> --
    >> Thanks,
    >> Fred
    >> Please reply to newsgroup, not e-mail
    >>
    >>
    >>

    >
    >




  4. #4
    Robin Hammond
    Guest

    Re: On Error Goto ignored

    Don't know. Easier to build the function once and use it lots of times
    though.

    Robin Hammond
    www.enhanceddatasystems.com

    "Fred Smith" <[email protected]> wrote in message
    news:[email protected]...
    > That's a workaround I hadn't thought of, and I could see using it
    > sometime. Buy why was my On Error Goto ignored?
    >
    > --
    > Regards,
    > Fred
    > Please reply to newsgroup, not e-mail
    >
    >
    > "Robin Hammond" <[email protected]> wrote in message
    > news:[email protected]...
    >> Fred,
    >>
    >> something like this
    >>
    >> Function SheetExists(strName As String) As Boolean
    >> Dim shName As Worksheet
    >> On Error Resume Next
    >> Set shName = Sheets(strName)
    >> On Error GoTo 0
    >> SheetExists = Not shName Is Nothing
    >> End Function
    >>
    >> Robin Hammond
    >> www.enhanceddatasystems.com
    >>
    >> "Fred Smith" <[email protected]> wrote in message
    >> news:Od%[email protected]...
    >>>I wanted to determine whether a sheet existed in the active workbook. So
    >>>I used:
    >>>
    >>> On Error Goto NoPerfSheet
    >>> Sheets("Performance").Select
    >>> On Error Goto 0
    >>>
    >>> However, Excel always stopped at the Sheets command, with a Subscript
    >>> out of range error.
    >>>
    >>> I knew there would never be more than two sheets in the workbook, so I
    >>> got it working by using:
    >>>
    >>> IF Sheets.Count = 1 Goto NoPerfSheet
    >>>
    >>> However, I'm why the On Error statement was ignored.
    >>>
    >>> What conditions causes VBE to ignore On Error?
    >>>
    >>> --
    >>> Thanks,
    >>> Fred
    >>> Please reply to newsgroup, not e-mail
    >>>
    >>>
    >>>

    >>
    >>

    >
    >




  5. #5
    Earl Kiosterud
    Guest

    Re: On Error Goto ignored

    Fred,

    Your code runs as it should on my XL2002.

    On Error GoTo NoPerfSheet
    Sheets("Performance").Select
    On Error GoTo 0
    Exit Sub
    NoPerfSheet:
    MsgBox "NoPerfSheet"

    --
    Earl Kiosterud
    mvpearl omitthisword at verizon period net
    -------------------------------------------

    "Fred Smith" <[email protected]> wrote in message
    news:Od%[email protected]...
    >I wanted to determine whether a sheet existed in the active workbook. So I
    >used:
    >
    > On Error Goto NoPerfSheet
    > Sheets("Performance").Select
    > On Error Goto 0
    >
    > However, Excel always stopped at the Sheets command, with a Subscript out
    > of range error.
    >
    > I knew there would never be more than two sheets in the workbook, so I got
    > it working by using:
    >
    > IF Sheets.Count = 1 Goto NoPerfSheet
    >
    > However, I'm why the On Error statement was ignored.
    >
    > What conditions causes VBE to ignore On Error?
    >
    > --
    > Thanks,
    > Fred
    > Please reply to newsgroup, not e-mail
    >
    >
    >




+ 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