Premium Only Content

Error Handling Methods in Excel VBA
You can download the workbook used in this video from the link below:
https://www.nomorelinesla.com/wp-content/uploads/2022/04/Excel-VBA-Error-Handling-Examples.zip
Error-handling is one of the most useful aspects of VBA, not just in Excel but also in other applications such as Outlook and Access. Error-handling allows you to capture and potentially correct an issue with your VBA code.
Anyone who has programmed in VBA has seen the Microsoft Visual Basic window appear when an error occurs executing code. For example, if your code selects a workbook that does not exist within the workbook collection, an Error 9 "Subscript Out of Range" error will appear in a message box. Without error-handling, this message box fatally terminates the subroutines/functions currently running.
Error-handling allows you to set aside code that help identify or fix a potential issue that can halt a critical process from executing. This is especially important for reliable automated reporting.
The first error handling option is called "On Error Resume Next". Think of the "On Error" line of code as a stoplight that instructs Excel on what to do when the next fatal error occurs. It does not apply to any preceding code. "On Error Resume Next" tells Excel to continue running the next step of the subroutine/function. As expected, this has benefits and determents and thought go into selecting the correct method of error-handling.
The next error-handling option is called "On Error GoTo". You can give a section of your code a heading, i.e., "On Error GoTo NextSection". "NextSection" with a colon (i.e. NextSection:) would then need to be present within your code. The "On Error GoTo" and your section heading would then divert your code to the "NextSection:" part of your code. It is recommended that you put your "On Error GoTo" error handling at the end of your code to prevent your error handling from running accidentially. A way of doing this is to type "Exit Sub" preceding your error-handling heading.
Lastly the final error-handling option is called "On Error GoTo 0". The main different between "On Error GoTo 0" and "On Error GoTo 'Heading'" is "On Error GoTo 0" is the off-switch to any On Errors currently enabled within the subroutine. Any code following "On Error GoTo 0" will throw a fatal error if an execution error occurs, nullifying any error-handling currently active.
Note: when the subroutine finishes, the error-handling deactivates.
-
2:05:01
TimcastIRL
3 hours agoTrump Just Ended H1B Visas In Major Crackdown, Charging $100k Per Visa | Timcast IRL
190K58 -
4:02:20
Nerdrotic
8 hours ago $10.35 earnedKimmel MELTDOWN | Hollywood Boycotts Disney | Friday Night Tights 372 with Kaida
76.4K12 -
34:08
Bannons War Room
3 hours agoMEGYN KELLY: Jimmy Kimmel and Sore Cultural Losers, and Charlie Kirk's Spiritual Revival, w/ Bannon
40.6K20 -
59:27
NAG Podcast
3 hours agoBrandon Straka: BOLDTALK with Angela Belcamino
21.5K7 -
59:43
Sarah Westall
1 hour agoVietnam Shuts down 86 Million Bank Accounts, The Fourth Turning & more w/ Andy Schectman
160 -
LIVE
Flyover Conservatives
8 hours agoMary Flynn O’Neill and Clay Clark: The Church Must Rise or America Falls | FOC Show
197 watching -
LIVE
I_Came_With_Fire_Podcast
11 hours agoThe Global ANTIFA Connection You've Never Heard Of | The Israel Question
245 watching -
16:38
RTT: Guns & Gear
18 hours ago $0.06 earnedExtar EP9 Review: The Best Budget 9mm PCC?
8.44K3 -
7:53
Rethinking the Dollar
11 hours agoMass Firings in Tech: The Real Agenda Behind 166,000 Cuts
2804 -
1:02:28
BonginoReport
5 hours agoFeds Monitor Threats Ahead of Kirk Memorial - Nightly Scroll w/ Hayley Caronia (Ep.138)
231K125