Master VBA Debugging in 20 Minutes

Поділитися
Вставка
  • Опубліковано 2 сер 2024
  • 👉 Ready to master VBA?
    - Check out my full courses: courses.excelmacromastery.com/
    - Subscribe to the channel here: bit.ly/36hpTCY
    -Want to download the source code for this video? Go here: shorturl.at/Ncam5
    (Note: If the download page doesn't work then make sure to turn off any popup blockers)
    Master VBA Debugging in 20 Minutes
    In this video, I'm going to cover everything you need to know about Debugging in VBA.
    * What is debugging and why you need it.
    * When to use the Locals window and when to use the Watch Window.
    * The SandBox Method
    * Putting it all together - a real-world example
    * Plus loads of cool tips and tricks you didn't know
    Useful VBA Shortcut Keys
    ========================
    Debugging:
    Compile the code: Alt + D + L OR Alt + D + Enter
    Run the code from the current sub: F5
    Step into the code line by line: F8
    Add a breakpoint to pause the code: F9(or click left margin)
    Windows:
    View the Immediate Window: Ctrl + G
    View the Watch Window: Alt + V + H
    View the Properties Window: F4
    Switch between Excel and the VBA Editor: Alt + F11
    View the Project Explorer Window: Ctrl + R
    Writing Code:
    Search keyword under cursor: Ctrl + F3
    Search the word last searched for: F3
    Autocomplete word: Ctrl + Space
    Get the definition of the item under the cursor: Shift + F2
    Go to the last cursor position: Ctrl + Shift + F2
    Get the current region on a worksheet: Ctrl + Shift + 8(or Ctrl + *)
    To move lines of code to the right(Indent): Tab
    To move lines of code to the left(Outdent): Shift + Tab
    Delete a Line: Ctrl + Y(note: this clears the clipboard)
    Table of Contents:
    00:00 - Introduction
    00:40 - What is Debugging?
    01:19 - Simple Debug Example
    01:50 - The Debug Toolbar
    02:25 - The Locals Window
    03:58 - The Watch Window
    05:03 - Watch Window: Using Functions
    06:20 - Tips for Debugging Ranges
    07:33 - Watch Window: Divide Conquer
    08:45 - Step Into/Over/Out
    11:31 - Run to Cursor
    11:59 - Set Next Statement
    12:48 - The Call Stack
    13:45 - Show Next Statement
    14:17 - Break in a loop
    15:43 - The Sandbox Method
    17:27 - Real-World Example
  • Наука та технологія

КОМЕНТАРІ • 61

  • @Excelmacromastery
    @Excelmacromastery  2 роки тому +6

    Enjoy the video. You can download the workbook I used in the description below. Let me know the most useful thing you learned from this video.

    • @ChristinaFranziska
      @ChristinaFranziska Рік тому

      Thanks for the great input! very valuable. Just, I can't download the file through the link given in the description. Can anyone assist? Thanks :-)

  • @tristanc6967
    @tristanc6967 2 роки тому +4

    So much great information in just 20 minutes. I'll definitely rewatch this a few times, but this will help me save so much time debugging. Thanks Paul!

  • @mrCetus
    @mrCetus 2 роки тому +1

    Yet another helpful masterpiece. Sir, Thank you for this wonderful explanation. I am still learning excellent VBA tricks from you. It's Awesome.

  • @junkertom7766
    @junkertom7766 26 днів тому

    Thanks for this video. For me it didn't contain much new stuff, but I recommend this video all the time to VBA beginners: friends, colleagues and on Stack Overflow.

  • @jimfitch
    @jimfitch 2 роки тому +3

    Wow, Paul! I’ve been debugging the hard way for so long … like using a hand shovel when a bulldozer is right there. Thank you!

  • @KM-co5mx
    @KM-co5mx 2 роки тому +2

    Thank You! Knowing how to debug is just as important as knowing how to code.

  • @simplejuan
    @simplejuan 2 роки тому +3

    Thank you for this video. I've been missing a lot of things in debugging my vba. This is very helpful. Breaking in a loop is awesome. I have been struggling with that. Now I know how. Thanks again

  • @outby50
    @outby50 2 роки тому +4

    Great intro. (In decades of using VBA, I'd never pondered what Set next statement even meant. Too soon old, too late smart.) Two comments:
    1) the advantage of Run to cursor vs setting a breakpoint is you don't have to clear the breakpoint afterwards if you don't want to keep stopping there during this session.
    2) I'm somewhat surprised you never mentioned the Immediate window. Some of the things you showed for watch are occasionally better suited to Immediate (i.e., ? x+7700). Also, Immediate allows you to modify variable values on-the-fly (i.e., loopcount=maxloopcount-1). Not to mention Debug.Print...

  • @stevegarwood3840
    @stevegarwood3840 2 роки тому +4

    This is great. I've also been exploring the usefulness of debug.assert to stop when a value doesn't match what's expected. Not sure if there's any advantage over a watch.

  • @freeliberalminds
    @freeliberalminds 2 роки тому +1

    Great VBA knowledge sharing sir Paul. So much thankful. God bless you.

  • @munshirasimraja5713
    @munshirasimraja5713 Рік тому

    Wonderful lesson of debugging code.
    I am very grateful for the video.
    Thanks u

  • @ricardoantunes9134
    @ricardoantunes9134 2 роки тому +2

    Thanks for sharing these very useful tips!! It will help me a lot

  • @bydlosith
    @bydlosith 10 місяців тому

    I wish I watched this video couple months ago, but only hours of painful debugging made me look for it :) thanks!

  • @wayneedmondson1065
    @wayneedmondson1065 2 роки тому +1

    Thanks Paul. Great, as always! Thumbs up!!

  • @WordBaron
    @WordBaron 2 роки тому

    The "Break When Value Is True" Watch option is especially valuable. Thank you!

  • @joaocustodio2094
    @joaocustodio2094 2 роки тому

    And once again I left with more knowledge of vba. Thanks Paul.

  • @olivermason8037
    @olivermason8037 Рік тому

    Concise and super informative, thank you!

  • @rafaelsilvareghin2017
    @rafaelsilvareghin2017 2 роки тому

    wow, I've been debugging for years and still learned a lot from your video, ty

  • @kimfucku8074
    @kimfucku8074 2 роки тому +1

    Another master class!

  • @kentokawaguchi8210
    @kentokawaguchi8210 Рік тому

    Great and knowledgeable video. Thanks for making it and sharing it with us.

  • @ryanmattson1546
    @ryanmattson1546 2 роки тому

    Thanks for the video. Very helpful!

  • @donuteater
    @donuteater 2 роки тому +1

    Gracias, aprendi cosas nuevas

  • @renyongsun9102
    @renyongsun9102 Рік тому

    Unbelievably informative video! Thank you for making it!

  • @Pedritox0953
    @Pedritox0953 2 роки тому +1

    Awesome video!

  • @jerzykepinski
    @jerzykepinski 2 роки тому +1

    Thanks man!

  • @buzan.untung
    @buzan.untung 2 роки тому +1

    Thank you

  • @KaiWeissmann
    @KaiWeissmann 2 роки тому

    Thanks a lot for the great content!

  • @alializadeh8195
    @alializadeh8195 Рік тому

    Thanks

  • @m_marcamo
    @m_marcamo 2 роки тому

    Really usefull, thanks Paul

  • @pegwinn
    @pegwinn Рік тому

    Thank you. I am not an excel pro. So when my simple macros break it is traumatic to say the least. I appreciate your tutorial videos.

  • @johnwayne8059
    @johnwayne8059 2 роки тому

    Nice Video Mr. VBA!👍👍👍🤟😎

  • @SimpleExcelVBA
    @SimpleExcelVBA 2 роки тому

    I didn't think I could get anything new from the video, but... this 'Add Watches & Break if True' is really cool tip. Thank You for that :)
    Maybe I have something for You - do You know that You can manually move the yellow line (break mode) some lines further or before? It helps me a lot in debugging.

  • @gopikasnair2813
    @gopikasnair2813 Рік тому

    Useful❤😂

  • @laurie93001
    @laurie93001 2 роки тому +1

    I'm relatively new to vba and self taught, I often read that "call" is depreciated and "application.run" should be used instead? What are the advantages and disadvantages of each?

    • @Excelmacromastery
      @Excelmacromastery  2 роки тому +1

      Call is not required but I like using it as it makes the code a little bit more readable.

  • @xs6819
    @xs6819 Рік тому

    Well how do you step on I cant even get the yellow arrow to highlight the next line?

  • @artistryartistry7239
    @artistryartistry7239 Рік тому

    1:27 I wrote the code exactly as you did. Whenever I try to step through windows just gives me an error chime. Any ideas please?

  • @peajayjay3622
    @peajayjay3622 2 роки тому

    Excel Macro Mastery...I need help! I have been running into a brick wall concerning PasteSpecial x1PasteValues error. How do I correct this error? If you've explained this specific example, please please point me to your video. Thanks!!

  • @WordBaron
    @WordBaron 2 роки тому +1

    Do you have any examples where a function can be used in the "Break When Value Is True" Watch option is used? I'm trying to figure out where in my code a particular data connection is getting inadvertently moved/renamed which causes subsequent data refresh steps to fail. I created a function that should tell me if the Connection exists but adding it to the watch window [via something like ConnExists("Connection Name")] always shows "" and I wasn't sure if something like a function that returns a Boolean could be used in a "Break When Value Is True" watch option. 🤔

    • @Excelmacromastery
      @Excelmacromastery  2 роки тому +1

      I don't think you can do that with a function. If possible you could return the function to a variable and put the watch on that.
      Another idea is to use the Debug.Assert line which will pause if the condition is false. See this video for more about Debug.Assert(ua-cam.com/video/CT7XkPXKVFw/v-deo.html)

  • @rahul7rock
    @rahul7rock 2 роки тому +5

    Yet another helpful masterpiece. Sir, Thank you for this wonderful explanation. I am still learning excellent VBA tricks from you. It's Awesome.