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.
-
LIVE
Badlands Media
16 hours agoDevolution Power Hour Ep. 345
17,177 watching -
LIVE
SpartakusLIVE
10 hours agoFIRST Pick of the Fourth Round for the $100,000 Tournament
5,129 watching -
1:35:07
Man in America
12 hours agoPeptides: Ultimate Health Hack… or Big Pharma Gila Monster POISON? w/ Dr. Diane Kazer
23.1K19 -
16:18
Mrgunsngear
3 hours ago $0.11 earnedBlack Aces Tactical S4 Tactical - Benelli M4 Clone But Does It Work?
4.6K3 -
2:05:15
Right Side Broadcasting Network
4 hours agoLIVE REPLAY: President Trump Attends UFC Fight 314 - 4/12/25
54.5K9 -
LIVE
BlackDiamondGunsandGear
2 hours agoWho’s in Town for This Stream?
253 watching -
32:55
The Connect: With Johnny Mitchell
22 hours ago $0.02 earnedInside America's LARGEST Pot Trafficking Gang: How Florida Fishermen Became #1 Most Wanted Cartel
4.37K -
1:24:56
Quite Frankly
12 hours ago"Wild Tales: Crazy Story Hotline" | The Brothers Ep. 1
31.3K9 -
12:37
Tundra Tactical
9 hours ago $0.52 earned🚫🚫 Biden Era GUN CONTROL Gone!!!! 🚫🚫
27K10 -
1:00:09
Motherland Casino
1 hour ago $0.01 earnedCynthia X Mia
5.07K1