VBA - variable declaration

J

Jeff

Hi,

I have a few macros that are being edited.
My question - is there a way to tell if a declared variable
has been used in the "sub Marcro()" or if it was just declared (i.e. dim
Variable3 as double) and not used.

This would be useful because it would allow me to more easily delete unused
variables and eliminate clutter.

Thanks
 
J

JE McGimpsey

Since it's only a few macros, the easiest way would probably be to use
Find() with the variable name in the VBE, which has an option to look in
the current procedure.

If you require variable declaration (which you absolutely should) by
using Option Explicit, you could also comment out the declaration of
suspect variables, then compile - if the variables are used, it will
generate a compile error, if not, you're free to delete the declaration.
 
K

Kevin B

If the first line in the module is not OPTION EXPLICIT, enter it so that all
variables have to be declared before using them and do the following:

Place an apostrophe at the beginning of the DIM statement to make the
declaration a comment

Recompile the code by clicking DEBUG and selecting COMPILE VBA PROJECT.

If it compiles OK the variable was not used.
 
B

Bob Phillips

Download MZ-Tools, it has a facility to analyze a project and it tells you
that. It is free.

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
Top