Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 921
Default VBA - variable declaration

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
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,624
Default VBA - variable declaration

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.


In article ,
Jeff wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,316
Default VBA - variable declaration

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.
--
Kevin Backmann


"Jeff" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,593
Default VBA - variable declaration

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)



"Jeff" wrote in message
...
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
type declaration characters integreat Excel Discussion (Misc queries) 3 July 18th 06 04:31 PM
type declaration characters integreat Excel Discussion (Misc queries) 1 July 17th 06 10:02 PM
Macro / Compile Error / Duplicate Declaration carl Excel Worksheet Functions 1 June 29th 05 08:55 PM
Last rites declaration of Ioannes Paulus PP. II (Karol Wojtyla) Ioannes Paulus PP. II (Karol Wojtyla) Charts and Charting in Excel 0 April 4th 05 01:49 AM
Use DocProps in a change declaration chris w Excel Worksheet Functions 7 January 21st 05 11:35 PM


All times are GMT +1. The time now is 08:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"