A Simple Way to Implement VBA Error Handling

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

A Simple Way to Implement VBA Error Handling

The video provides a simple way to implement effective error handling for your Excel VBA projects.


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:29 - The Err.Raise Statement
04:27 - A Simple Code Design
06:48 - A Simple Error Handling Strategy
Рекомендации по теме
Комментарии
Автор

Sub Thanks(sReason As String)
Dim NewLine as String
NewLine=vbCrLf
MsgBox("Thank you Sir" & NewLine & sReason)
End Sub

Call Thanks("You saved my life with that piece of code!!!")

stavrosdimoudis
Автор

Terrific approach, especially as it retraces the entire stack of procedure calls. I've learned so much from subscribing to your channel. Cheers, Brendan

bpbeary
Автор

Thanks for this Paul. I hve learned a lot.

ryancagulang
Автор

This is really good stuff mate, thank you so much!

joetester
Автор

Very useful
You are the best Excel-related YouTuber. Thank you again. Mary Christmas.

iincitr
Автор

Paul awesome content.
You have given key value on VBA language. We have never come across such a useful error handling procedure.
Merry X'Mas 😄😃😍
Big Thumbs up 👍👍👍

hemant
Автор

Thank you my friend for the code file. It's great

Fshhady
Автор

Thank you Paul!!! I need to test it asap.

mike_case
Автор

This the most useful strategy I have found on the internet. Unfortunately, it doesn't seem to work when you use it on userforms. When the error is found inside of a command button of a userform, the code stops where the err.raise line is located. That was very frustrating for me not to be able of using this powerful strategy in my code. Besides that... Thanks very much for your incredible job :)

manuelefe
Автор

Thank you Paul sir. Your videos are very informative and it has helped me to purify my codes. 🤗

rahulrock
Автор

Great video! Can you show how to use named range in vba and how to setup named range?

alecmatias
Автор

Hey! I've been following your channel for some time now, im from and in Perú, your videos are awesome, I just wanted to ask, in this method, I understand that it's only one error per sub in every run right?

jimmyvelasco
Автор

Hi Paul, your tutorials are great! (I always recommend them to my friends). Thanks and keep them coming! Could you assist me to open the .bas file that has the code? Thanks in advance! And Happy Holidays!

bernardanim
Автор

Thank you for the great video. Unfortunately, when i import your fil, it only has the ErrorHandling Module. How do I download the other modules?

debbie
Автор

Excellent video. The problem with throwing errors is that with a large procedural subroutine, it is hard to know the cause. I have found that isolating a line of code that causes the error into a function that returns a boolean works in most cases because you can send the error to a label "eh:" in your function and return false to indicate that the function did not work correctly. I suppose you can have several labels and several goto labels as well. Is that possible? For me, isolating errors prone code into functions helps you ensure you know why your code is breaking and it allows you to control the next step.

markspindler
Автор

'Just recently came across your excellent videos, so not sure if you're still reading comments. If so, I've tried a number of ways to implement your error handling code to no avail (put the ErrorHandling module into a sandbox, copied test routines from your website and ran them, but message box with error readout doesn't come up). Is there some way of determining what is missing? I'd love to replace my current, klunkier error handling with this technique. Thx!

karenjoy
Автор

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
Автор

FYI, I have noticed the link to the code of this video (and some others) takes you to a broken link. Thanks

k
Автор

5:03 ?😜
Unexpected laughters... 😂😂😂😂

engrvarsi
Автор

00:12. Sir Paul recommends viewing the previous video on error handling
before viewing this video. Do it!

houstonvanhoy
join shbcf.ru