Need help debugging vba code

obener

Board Regular
Joined
May 31, 2009
Messages
118
Hi All,

Just wanted to know if there is an easy way of debugging a vba code. The vba code I have runs all the way through but when it is finished what I want it to do, it looks like it is still running the code, and I can see the mouse cursor change to loading status and when I press esc button I dont get an error of I stopped the code. What would be the best way on to go about it?

Thanks
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
I use Debug.Print <Some variable>, to print to the Immediate Window, along the way to see how far the code has progressed before choking.
 
Upvote 0
I use Debug.Print <some variable="">, to print to the Immediate Window, along the way to see how far the code has progressed before choking.

I am using Debug.print but the immediate window or locals is just blank cant see anything on there.</some>
 
Upvote 0
There are various ways to debug code.

You could simply step through it line by line with F8.

If there is specific section of code you want to look at you can set up a breakpoint (F9) just before it, run the code and it will stop at the breakpoint and you can step through (F8).

If you want to check the values of variables while the code is running you can add Watchs on them, then they'll appear in the Watch window.

To add a watch on a variable you can just drag it to the Watch window.

David's suggestion is pretty handy to, how are you using it?
 
Upvote 0
There are various ways to debug code.

You could simply step through it line by line with F8.

If there is specific section of code you want to look at you can set up a breakpoint (F9) just before it, run the code and it will stop at the breakpoint and you can step through (F8).

If you want to check the values of variables while the code is running you can add Watchs on them, then they'll appear in the Watch window.

To add a watch on a variable you can just drag it to the Watch window.

David's suggestion is pretty handy to, how are you using it?

I was just using debug.print without anything else which was printing a blank line. After I changed it to debug.print "passed line" It worked. When the code loops multiple times F8 can be slow and annoying but I didnt know you could set a breakpoint and then step through, always something new to learn. I think I have a small idea on where it is messing up, I will have to just review it and see if I get anywhere with it. Thanks Norie and Tinbendr
 
Upvote 0
To set a breakpoint just select the line where you want it and hit F9 then run the code as normal.

A breakpoint is quite handy for a loop, just put one on the first line of the loop.

Then you can step through the code within the loop.

You don't need to step through every iteration, just hit F5 to restart the code.
 
Upvote 0

Forum statistics

Threads
1,211,983
Messages
6,105,208
Members
447,955
Latest member
BWheezy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top