EXCEL How to use Debug mode.

Anonymous
2022-05-30T13:38:43+00:00

I have a very old spreadsheet that I created probably 10 years ago, that has a bug that I suspect is within the VBA code. It's been years since I've worked with VBA. I need help with the fundamental details of using the Debug feature. For starter, I want to pause the execution at very start of the Open routine. Do I just need to set a breakpoint at the beginning of the Open? Beyond that I need to know how step through execution one command at a time.

My target is to understand how a switch is getting set, that is supposed to be set by the user in the MAIN routine.

I'm open to consulting some resource available, such as a knowledge base article. I'm not keen on just diving in and hacking away at the code.

TIA for your help.SweetTasha

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

9 answers

Sort by: Most helpful
  1. Anonymous
    2022-05-30T14:21:14+00:00

    Go into the macro editor

    Put the cursor at the start of the macro

    <F5> will run the macro

    <F8> will advance 1 line (execute current line, move to the next line

    .

    You can set "watch points" , or "break points" (to stop execution), you can type commands into the "Immediate" window to see values.

    https://www.myonlinetraininghub.com/debugging-vba-code

    https://www.tutorialspoint.com/excel_macros/excel_macros_debugging_code.htm

    https://www.mrexcel.com/excel-tips/debugging-vba-macro/ (video and example file https://corporatefinanceinstitute.com/resources/excel/study/vba-how-to-debug-code/

    https://www.excel-easy.com/vba/examples/debugging.html

    0 comments No comments
  2. Anonymous
    2022-05-30T16:06:32+00:00

    Hi, I'm Elise, and I'd be happy to help with your issue.

    That is right, if you set a breakpoint in the code, then you can just step through the code using F8

    There is a good guide here on other methods too:

    https://www.wiseowl.co.uk/blog/s196/step-throug...

    Please let me know if you need any further assistance.

    Kind Regards,

    Elise

    Note: This is a non-Microsoft website. The page appears to be providing accurate, safe information. Watch out for ads on the site that may advertise products frequently classified as a PUP (Potentially Unwanted Products). Thoroughly research any product advertised on the site before you decide to download and install it.

    0 comments No comments
  3. Anonymous
    2022-05-30T16:43:06+00:00

    > ...My target is to understand how a switch is getting set, that is supposed to be set by the user in the MAIN routine.

    Just another idea is to right-click your variable and add it to the Watch list.

    You can just run your code normally, and it will break when the value changes.

    1 person found this answer helpful.
    0 comments No comments
  4. Anonymous
    2022-05-30T21:48:46+00:00

    Rand2201 Thanks for your reply.

    I Developer>visual basic>Debug>Add watch. How do I find the switch I want to watch? I know its name with the spreadsheet, but not in Debug?

    Thanks. SweetTasha

    0 comments No comments
  5. Anonymous
    2022-05-30T22:10:23+00:00

    ronski2 Thanks for your reply.

    you say

    Go into the macro editor

    Put the cursor at the start of the macro

    Somewhere is says Alt+F11 opens the vba editor. I did that. Now how do I know what macro I want to look at.

    Thanks. SweetTasha.

    0 comments No comments