VBA Error Handling Explained in Plain English (with examples)

preview_player
Показать описание
👉 Ready to master VBA?
(Note: If the download page doesn't work then make sure to turn off any popup blockers)

VBA Error Handling Explained in Plain English (with examples)

Useful VBA Shortcut Keys:
Compile the code: Alt + D + C or Alt + D + Enter
Run the code from the current sub: F5
Step into the code line by line: F8
View the Immediate Window: Ctrl + G
View the Watch Window: Alt + V + H
Auto complete word: Ctrl + Space

Shift + F2: Get the definition of the item under the cursor.
Ctrl + Shift + F2: Go to the last cursor position.
Alt + F11: Switch between Excel and the VBA Editor.
Ctrl + R: View the Project Explorer Window.
Ctrl + Shift + 8(or Ctrl + *): Get the current region on a worksheet.
Tab: To move lines of code to the right(Indent).
Shift + Tab: To move lines of code to the left(Outdent).
F4: View the Properties Window.
F9(or click left margin): Add a breakpoint to pause the code.

Table of Contents:

00:00 - Introduction
00:24 - Ensure the error settings are correct
00:55 - Remove all Compile errors
02:45 - Dealing with Runtime Errors
04:45 - The 3 Error Handling States
06:57 - On Error Goto 0
08:09 - On Error Resume Next
10:22 - On Error Goto [label]
15:18 - Cleaning up after an error occurs
17:54 - Turning off Error Handling
19:03 - Unwinding the code
21:19 - Error Handling in a Nutshell
21:23 - Recap
Рекомендации по теме
Комментарии
Автор

best explanation on error I had! Thanks Paul!

EduardoRibeiroEdu
Автор

You're a great teacher. Awesome Content.

tdtrecordsmusic
Автор

Paul, thanks for this video and explaining how the code does not stop at the error handling label (eh:) if there is not an error. I was never too sure about that.

darray
Автор

Thank you and much appreciated. This was great for me as I am self taught and a newbie in coding and don't know what I am doing half the time. With your help things are getting better.

elainestewart
Автор

Thank you Paul for this instruction. It's very helpful :)

mike_case
Автор

Thank you so much for these videos. Love them, so helpfull. Am doiing your Basics course at the moment and have learned so much. Just wanted to let you know i appreciate your time and

stevec
Автор

Thanks, Paul, very helpful and useful.

JohnOvens
Автор

clear as a bell, just need to practice implementing these strategies, thanks looking forward to part two!

micmike
Автор

Thanks! Great tutorial man. Nicely done!

wayanfjwork
Автор

Hi Paul, another excellent video, thank you for this. All your videos are refresher and I always learn a bit more each time.
Looking forward to watching your next video "Error Handling Strategy" :-)

infamemoriarty
Автор

Amazing! Zero Dislikes! Best teacher in youtube!

AI-ecqb
Автор

Boy have I been making errors in my error handling. Thanx for the advice and teaching an old dog new tricks. Just an FYI, the info in "More" has a minor typo FREE CHEAT SHEET: Get the free cheat sheet on VBA arrays here, but the cheat sheet is actually errors. Thanx again for all.

jerryjones
Автор

Implement functionality: 20% effort
Error trapping, user experience: 100% effort
Learning to calculate: Priceless

thearchibaldtuttle
Автор

Thank you Paul. 👏 I really wish you will get too many new subscribers on your valuable channel. Thanks for all your efforts. Salim

sasavienne
Автор

as always: simple, elegant, clear. Thanks mate.

andywawa
Автор

Thank you Paul! Really helpful. ... for e.g., will think 3 times before adding "Resume Next" into code.

andreykapustin
Автор

Can you also add explanation about on error go to -1. Thank you for this one.

sujatadhamale
Автор

Great content! Thank you for sharing your knowledge!
My team has quite a few macros. Most of them open log files, read data, validates and extracts data on log files based on the position in the row. Then finally generats ouput files (log file) with the information based on the matched criteria. Most of the times because of extra spaces or characters macro not able to read data on source files (log files) and providing error messages.
Could you please upload a video with log files and how to identify source file and the line of souce file where the error coming from?

Thank you in advance!

kishi
Автор

Paul, you have given very good example even beginner level coder can understand.
Kudos :)
However it would be helpful if you can include the some example about
on error goto 0, 1 and -1.


Also we are keen to know trick how we can handle error if subsequent procedure doen't impact if base procedure has any errors.


Waiting for next release.
Good job :) :)

hemant
Автор

Can you have an error handling label in the middle of the subroutine instead of at the end after your "Done:" label?

tomschopler