Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4622360
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:49:56+00:00 2026-05-22T02:49:56+00:00

I’ve been working with VBA for quite a while now, but I’m still not

  • 0

I’ve been working with VBA for quite a while now, but I’m still not so sure about Error Handling.

A good article is the one of
CPearson.com

However I’m still wondering if the way I used to do ErrorHandling was/is completely wrong:
Block 1

On Error Goto ErrCatcher
   If UBound(.sortedDates) > 0 Then

       // Code

   Else
ErrCatcher:
       // Code

   End If

The if clause, because if it is true, will be executed and if it fails the Goto will go into the Else-part, since the Ubound of an Array should never be zero or less, without an Error, this method worked quite well so far.

If I understood it right it should be like this:

Block 2

On Error Goto ErrCatcher
    If Ubound(.sortedDates) > 0 Then

       // Code
    End If

    Goto hereX

ErrCatcher:
       //Code
    Resume / Resume Next / Resume hereX

hereX:

Or even like this:
Block 3

On Error Goto ErrCatcher
    If Ubound(.sortedDates) > 0 Then

       // Code
    End If

ErrCatcher:
    If Err.Number <> 0 then
       //Code
    End If

The most common way I see is that one, that the Error “Catcher” is at the end of a sub and the Sub actually ends before with a “Exit Sub”, but however isn’t it a little confusing if the Sub is quite big if you jump vice versa to read through the code?

Block 4

Source of the following Code:
CPearson.com

  On Error Goto ErrHandler:
   N = 1 / 0    ' cause an error
   '
   ' more code
   '
  Exit Sub

  ErrHandler:

   ' error handling code'

   Resume Next

End Sub 

Should it be like in Block 3 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:49:57+00:00Added an answer on May 22, 2026 at 2:49 am

    I definitely wouldn’t use Block1. It doesn’t seem right having the Error block in an IF statement unrelated to Errors.

    Blocks 2,3 & 4 I guess are variations of a theme. I prefer the use of Blocks 3 & 4 over 2 only because of a dislike of the GOTO statement; I generally use the Block4 method. This is one example of code I use to check if the Microsoft ActiveX Data Objects 2.8 Library is added and if not add or use an earlier version if 2.8 is not available.

    Option Explicit
    Public booRefAdded As Boolean 'one time check for references
    
    Public Sub Add_References()
    Dim lngDLLmsadoFIND As Long
    
    If Not booRefAdded Then
        lngDLLmsadoFIND = 28 ' load msado28.tlb, if cannot find step down versions until found
    
            On Error GoTo RefErr:
                'Add Microsoft ActiveX Data Objects 2.8
                Application.VBE.ActiveVBProject.references.AddFromFile _
                Environ("CommonProgramFiles") + "\System\ado\msado" & lngDLLmsadoFIND & ".tlb"
    
            On Error GoTo 0
    
        Exit Sub
    
    RefErr:
            Select Case Err.Number
                Case 0
                    'no error
                Case 1004
                     'Enable Trust Centre Settings
                     MsgBox ("Certain VBA References are not available, to allow access follow these steps" & Chr(10) & _
                     "Goto Excel Options/Trust Centre/Trust Centre Security/Macro Settings" & Chr(10) & _
                     "1. Tick - 'Disable all macros with notification'" & Chr(10) & _
                     "2. Tick - 'Trust access to the VBA project objects model'")
                     End
                Case 32813
                     'Err.Number 32813 means reference already added
                Case 48
                     'Reference doesn't exist
                     If lngDLLmsadoFIND = 0 Then
                        MsgBox ("Cannot Find Required Reference")
                        End
                    Else
                        For lngDLLmsadoFIND = lngDLLmsadoFIND - 1 To 0 Step -1
                               Resume
                        Next lngDLLmsadoFIND
                    End If
    
                Case Else
                     MsgBox Err.Number & vbCrLf & Err.Description, vbCritical, "Error!"
                    End
            End Select
    
            On Error GoTo 0
    End If
    booRefAdded = TRUE
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.