A Simple Way to Implement VBA Error Handling

Поделиться
HTML-код
  • Опубликовано: 27 дек 2024

Комментарии • 73

  • @stavrosdimoudis1524
    @stavrosdimoudis1524 5 лет назад +4

    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!!!")

  • @bpbeary8011
    @bpbeary8011 5 лет назад +3

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

  • @iincitr
    @iincitr 5 лет назад +1

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

  • @debbie6085
    @debbie6085 Месяц назад

    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?

  • @joetester4007
    @joetester4007 9 месяцев назад

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

  • @ryancagulang8728
    @ryancagulang8728 Год назад

    Thanks for this Paul. I hve learned a lot.

  • @hemant0088
    @hemant0088 5 лет назад +1

    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 👍👍👍

  • @Fshhady
    @Fshhady Год назад

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

  • @manuelefe21
    @manuelefe21 4 года назад +2

    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 :)

  • @karenjoy511
    @karenjoy511 Год назад

    '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!

  • @wayneedmondson1065
    @wayneedmondson1065 3 года назад

    Thanks Paul!

  • @thearchibaldtuttle
    @thearchibaldtuttle 5 лет назад +7

    Merry X-Mas and an error free 2020!

  • @markspindler5321
    @markspindler5321 Год назад

    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.

  • @kishi3987
    @kishi3987 Год назад

    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!

  • @alecmatias4774
    @alecmatias4774 2 года назад

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

  • @rahul7rock
    @rahul7rock 4 года назад

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

  • @jimmyvelasco1570
    @jimmyvelasco1570 5 лет назад +1

    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?

    • @Excelmacromastery
      @Excelmacromastery  5 лет назад +2

      Yes. But the code will exit at the first error so it wouldn't reach any other errors.

    • @jimmyvelasco1570
      @jimmyvelasco1570 5 лет назад

      @@Excelmacromastery Niceee

  • @valentinneufeld6182
    @valentinneufeld6182 2 года назад

    This is awesome 👌

  • @xaviercohen1124
    @xaviercohen1124 5 лет назад

    Hi Paul, thanks a lot for your video, they are very useful... just one question please: I checked on my Excel when clicking any module(right click) in my VBA editor, I do not have the option "add line number"... I do not understand, I am currently using Excel 2016... thanks a lot in advance for your feedback...

    • @xaviercohen1124
      @xaviercohen1124 5 лет назад

      I listened again your video, you said that you used MZ tool to do that but it is not free...but alternatively it is possible to program something ourselves...

    • @Excelmacromastery
      @Excelmacromastery  5 лет назад

      It is possible to write your own code to do it but it's not trivial to do so.

  • @mike_case
    @mike_case 5 лет назад

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

  • @kevinbezant8972
    @kevinbezant8972 5 лет назад

    Hi Paul, great video. Out of interest, why do you pass the parameters to RaiseError and DisplayError subs as ByVal?

    • @Excelmacromastery
      @Excelmacromastery  5 лет назад

      It means that only the value is passed. So if the value is changed in the sub it will be changed in the original.

  • @scotolivera8207
    @scotolivera8207 5 лет назад

    You make VBA look easy 😃

  • @k0023382
    @k0023382 9 месяцев назад

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

  • @stevennye5075
    @stevennye5075 5 лет назад

    This was very helpful!

  • @bernardanim2381
    @bernardanim2381 5 лет назад

    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!

    • @Excelmacromastery
      @Excelmacromastery  5 лет назад +1

      Right click on the workbook in the project window. Select "Import File" and then select the .bas file

    • @bernardanim2381
      @bernardanim2381 5 лет назад

      @@Excelmacromastery Thanks!

  • @arjen421
    @arjen421 4 года назад

    Great video! The download link for the error handling code however seems to be dead. I'm just getting a white screen.

    • @Excelmacromastery
      @Excelmacromastery  4 года назад

      This is caused by using a pop up blocker like uBlock Origin. Try turning it off or using incognito.

    • @arjen421
      @arjen421 4 года назад

      @@Excelmacromastery I was indeed using ublock. Got it now and working great. Thx

  • @kamatchinmay
    @kamatchinmay 5 лет назад

    Excellent strategy

  • @123petz
    @123petz 4 года назад

    Is there any requirement that you add declared constant vbObjectError value + 1
    Const Error_Total_Value = vbObjectError + 1

  • @321tryagain
    @321tryagain 5 лет назад

    Helpful, thank you

  • @Naresh13Kumar
    @Naresh13Kumar 5 лет назад

    Hello how did u update the number to the code automatically, can we able create our own tool, like that as a developer tool to faster the code writing method!

    • @Excelmacromastery
      @Excelmacromastery  5 лет назад

      I used a third party tool. You can write code to do it but it's advanced.

  • @mikemorrione8899
    @mikemorrione8899 4 года назад

    Does your error handling code work for access vba?

  • @chrisedwards670
    @chrisedwards670 5 лет назад

    Unable to download the code page times out
    This site can’t be reached
    bit.ly took too long to respond.

    • @Excelmacromastery
      @Excelmacromastery  5 лет назад

      I just checked it an it seems fine. Are you using a VPN by any chance?

  • @sandeepkothari5000
    @sandeepkothari5000 5 лет назад

    Great going Paul.
    I downloaded the .bas file. How to open it?

  • @SachinKumar-xf7ss
    @SachinKumar-xf7ss Месяц назад

    Method 'SaveAs' of object '_Worksheet' failed" sometime , iam getting this error, could you please tell us cause and solve the error
    You’re invited to try

  • @Meolimo
    @Meolimo 5 лет назад

    one word : Wow
    tks :-)

  • @kailash680
    @kailash680 3 года назад

    Download is not possible, just a blank website.

  • @engrvarsi3774
    @engrvarsi3774 5 лет назад

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

  • @houstonvanhoy7767
    @houstonvanhoy7767 3 года назад +1

    00:12. Sir Paul recommends viewing the previous video on error handling
    ruclips.net/video/gKIOIXriXEI/видео.html
    before viewing this video. Do it!

  • @shreyasiparikh1544
    @shreyasiparikh1544 4 года назад

    Can you tell what is error
    If txt.Value = "" Or txt.Value = Field_Type Then
    MsgBox "Please enter the " & Field_Type, vbCritical
    Exit Sub
    End If

    Dim Search_range As Range
    Set Search_range = sh.Range(sh.Cells(2, Col_number), sh.Cells(Application.Rows.Count, Col_number))
    If Application.WorksheetFunction.CountIf(Search_range, "*" & txt.Value & "*") = 0 Then
    MsgBox "No Match Found", vbCritical
    Exit Sub
    End If
    Dim iRow As Long
    If Application.WorksheetFunction.CountIf(Search_range, txt.Value) > 0 Then
    iRow = Application.WorksheetFunction.Match(txt.Value, Search_range, 0) + 1
    Else
    iRow = Application.WorksheetFunction.Match("*", & txt_value & "*", serach_range, 0) + 1
    End If

  • @vladyslavtverezyy2242
    @vladyslavtverezyy2242 4 года назад

    Hello. If i have the next Macro:
    Sub Copyrenameworksheet()
    'Updateby Extendoffice 20160704
    Dim ws As Worksheet
    Set wh = Worksheets(ActiveSheet.Name)
    ActiveSheet.Copy After:=Worksheets(Sheets.Count)
    If wh.Range("A1").Value "" Then
    ActiveSheet.Name = wh.Range("A1").Value
    End If
    wh.Activate
    End Sub
    Home can i add an MsgBox that write "Sheet already exists"?

  • @searchingyt4246
    @searchingyt4246 4 года назад

    Hey Paul, Could you make a video about error handling within a while and for loop. On error do something and then jump to next loop iteration. That would be very helpful :)

  • @sane7263
    @sane7263 3 года назад

    the website never works !

  • @grahamparker7729
    @grahamparker7729 5 лет назад

    👍🏻

  • @exogendesign4582
    @exogendesign4582 4 года назад

    I AM SO stupid I dont understand!!!!😓😓😓😓😓😓