VBA Error Handling Explained in Plain English (with examples)

แชร์
ฝัง
  • เผยแพร่เมื่อ 25 ธ.ค. 2024

ความคิดเห็น • 58

  • @AI-ec2qb
    @AI-ec2qb 4 ปีที่แล้ว

    Amazing! Zero Dislikes! Best teacher in youtube!

  • @s1ngularityxd64
    @s1ngularityxd64 3 ปีที่แล้ว

    You made my day. Just amazing

  • @tdtrecordsmusic
    @tdtrecordsmusic 4 ปีที่แล้ว

    You're a great teacher. Awesome Content.

  • @jerryjones8836
    @jerryjones8836 2 ปีที่แล้ว

    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.

  • @elainestewart7188
    @elainestewart7188 3 ปีที่แล้ว

    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.

  • @micmike
    @micmike 4 ปีที่แล้ว

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

  • @wayanfjwork5037
    @wayanfjwork5037 3 ปีที่แล้ว

    Thanks! Great tutorial man. Nicely done!

  • @EduardoRibeiroEdu
    @EduardoRibeiroEdu 4 ปีที่แล้ว

    best explanation on error I had! Thanks Paul!

  • @infamemoriarty8432
    @infamemoriarty8432 5 ปีที่แล้ว +1

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

  • @stevec1835
    @stevec1835 3 ปีที่แล้ว

    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 efforts.....

  • @thearchibaldtuttle
    @thearchibaldtuttle 5 ปีที่แล้ว +2

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

  • @sasavienne
    @sasavienne 4 ปีที่แล้ว

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

  • @andreykapustin5080
    @andreykapustin5080 5 ปีที่แล้ว

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

  • @wayneedmondson1065
    @wayneedmondson1065 3 ปีที่แล้ว

    Thanks Paul!

  • @mike_case
    @mike_case 5 ปีที่แล้ว +1

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

  • @gregbernard7861
    @gregbernard7861 2 ปีที่แล้ว

    Great video.

  • @JohnOvens
    @JohnOvens 5 ปีที่แล้ว

    Thanks, Paul,very helpful and useful.

  • @andrewwest5344
    @andrewwest5344 3 ปีที่แล้ว

    THANK YOU

  • @sujatadhamale1194
    @sujatadhamale1194 3 ปีที่แล้ว +1

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

  • @andywawa7227
    @andywawa7227 3 ปีที่แล้ว

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

  • @rrki
    @rrki ปีที่แล้ว

    Thank you

  • @darray7472
    @darray7472 5 ปีที่แล้ว

    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.

  • @sanjeevirajendran9670
    @sanjeevirajendran9670 3 ปีที่แล้ว

    Nice subject

  • @jay55patel
    @jay55patel 4 ปีที่แล้ว

    thank you very helpful

  • @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!

  • @hemant0088
    @hemant0088 5 ปีที่แล้ว

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

    • @Excelmacromastery
      @Excelmacromastery  5 ปีที่แล้ว +1

      I show an example of goto 0. goto -1 is rarely needed and I thought it would confuse things. There is no goto 1.
      I will be covering error handling when the procedure is not the top most one. This will be in my next video.

  • @geoffreyjones3832
    @geoffreyjones3832 5 ปีที่แล้ว

    Not that I understand and can use this information but, I thank you for presenting it.

  • @PrincePedia
    @PrincePedia 5 ปีที่แล้ว

    Thanks Paul :)

  • @sandravukovic2901
    @sandravukovic2901 5 ปีที่แล้ว

    Hi Paul, thank you for such a nice explanation. One question: if the code is changing the data by looping through cells, and after a few cells runs into type mismatch error, is there a way to reverse the process other than putting everything into an array? Maybe letting the user correct the mistake in the cell and then continue with the loop?

    • @dtr406
      @dtr406 5 ปีที่แล้ว

      Sandra Vukovic I’m wondering the same also...

    • @Excelmacromastery
      @Excelmacromastery  5 ปีที่แล้ว +2

      Generally it's cleaner to terminate the current task, ask the user to fix the data and run it again.
      If you wanted to do it: You can use "Resume Next" after the error message. This will continue the code from the line after the error.
      You also need to set the loop variable back one to retry the code that failed. You could do this before the "Resume Next" line e.g. i=i-1.

    • @sandravukovic2901
      @sandravukovic2901 5 ปีที่แล้ว

      @@Excelmacromastery Yes, that's what I was thinking. I had an example in mind where one should add 10% increase to all prices in cells, and by starting the code from the beginning, all the prices that were already increased would be increased one more time. Thank you for the support!

  • @TSSC
    @TSSC 5 ปีที่แล้ว

    The tricky thing with error handling is to think about what can go wrong. It’s easy to think that everyone will do as intended. One needs to imagine what can go wrong (e.g. incorrect data or user input, user clicks on cancel or closes a user form or dialogue box) before being able to handle errors in a way that doesn’t confuse the users.

    • @Excelmacromastery
      @Excelmacromastery  5 ปีที่แล้ว

      Very true. You have treat "what can go wrong" as part of the project requirements so you know how the application should handle issues.

    • @houstonvanhoy7767
      @houstonvanhoy7767 3 ปีที่แล้ว +1

      @@Excelmacromastery Yes, Murphy's Law.

  • @tomschopler4094
    @tomschopler4094 11 หลายเดือนก่อน

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

  • @stavrosdimoudis1524
    @stavrosdimoudis1524 5 ปีที่แล้ว

    Thank you Sir. What if the error derives from another process (eg database query bad response)? Will the error handler catch it?

    • @Excelmacromastery
      @Excelmacromastery  5 ปีที่แล้ว

      Yes. It will give an error.

    • @redfern_mike
      @redfern_mike 5 ปีที่แล้ว

      @@Excelmacromastery How do you get the database object error code (object?) rather than the vba Err code

  • @CollDott
    @CollDott 3 ปีที่แล้ว +1

    👍

  • @ibh9999
    @ibh9999 2 ปีที่แล้ว

    Error Handling is suitably called 'handling potential error'.

  • @PhanchaiSiam555
    @PhanchaiSiam555 8 หลายเดือนก่อน

    555. My Userform is not loading at all on another PC. Excel just say cannot open file. LUL. In the macro is just a Userform1.show and the message say: Cannot open file.

  • @oluben3577
    @oluben3577 5 ปีที่แล้ว

    box script testing... txt

  • @tughanozsezer9332
    @tughanozsezer9332 5 ปีที่แล้ว

    .

  • @dariuszspiewak5624
    @dariuszspiewak5624 2 ปีที่แล้ว

    It's a real shame that M$ have for so many years not implemented the clean and elegant structured error-handling paradigm. We're stuck with this ugly spaghetti code >:\ Preposterous. This is why I try to shy away from VBA as much as possible. It's just plain ugly.

  • @GeezRvonFart
    @GeezRvonFart 5 ปีที่แล้ว

    great videos..

    • @Excelmacromastery
      @Excelmacromastery  5 ปีที่แล้ว

      Thank you GeezR

    • @GeezRvonFart
      @GeezRvonFart 5 ปีที่แล้ว

      @@Excelmacromastery i think your videos have a good amount of info in them, others often don't explain why a command does something or go too deep down the rabbit hole.