Stop on variable

J

Jos Vens

Hi,

does anyone know if it is possible to stop the VBA-code when it reaches (the
first) variable I have in mind.

eg. I am tracing for a variable when it changes from value but I don't know
anymore where it stands in my procedures, so I should like to ask excel to
stop whenever it encounters this specific variable (in stead of setting the
red dot in the margin or using the command Stop)

Thanks,
Jos Vens
 
S

Sharad

Where you defined the variable, define it wrong type.

E.g. Define the variable as Boolean, if actually it will be a string. Or
define it as Range if it is not going to a range at all.

Remove any On Error commands in the code.

So when the variable is first reached to assining a value, or to check
its value, you will get error 'Type Mismatch' or 'Object Variable or
With Block variable not set'.


Sharad
 
J

Jos Vens

Sorry Sharad,

I was thinking of a tool embedded in the VBA environment like the window
Direct where you can put the name of a variable and then Excel stops when it
encounters it.

I'm not prepared to run through thousands of lines to see if the On Error is
set or not.

Thanks anyway,
Jos
 
D

Dave Peterson

Inside the VBE:

Debug|Add watch

There's an option to "break when value changes"
 
J

Jos Vens

Thanks Dave,

it works perfect for tracing changing values of variables!

However, I also like to trace defined names like [myName]. If I add the
control to the window, it stops on every line of my code. Is this not
possible?

Jos
 
D

Dave Peterson

I couldn't do it.

I'm guessing that since the value in that range could change any time, VBA sees
it as something that might have changed. (But that's just a guess.)



Jos said:
Thanks Dave,

it works perfect for tracing changing values of variables!

However, I also like to trace defined names like [myName]. If I add the
control to the window, it stops on every line of my code. Is this not
possible?

Jos

Dave Peterson said:
Inside the VBE:

Debug|Add watch

There's an option to "break when value changes"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Flip comment to left 3
Making a PDF-file 4
Bug in multiselect listbox? 2
using variable in 7
Shortcut of menu-item 2
Detect printer properties 3
How to display value of global variable? 5
Public variable 7

Top