![]() |
Resetting variables
Is there a way to reset all variables in a macro? When I run it the first
time my results match my control results perfectly, but when I run it again the numbers are all wrong. TIA. -gk- |
Resetting variables
The End statement immediately clears all variables (and terminates macro
execution). -- Jim Rech Excel MVP |
Resetting variables
If your variables are delcared with Dim in the sub then they should reset
when the routine ends. If you declare them with Static then they will retain there values between calls. If your variables are delcared as Public at the top of a module they will retain their values after code has ended and other procedures can see the Public variable values also. Variables declared using the Public statement are available to all procedures in all modules in all applications unless Option Private Module is in effect; in which case, the variables are public only within the project in which they reside. -- Regards, Rocky McKinley "TBA" wrote in message ... Is there a way to reset all variables in a macro? When I run it the first time my results match my control results perfectly, but when I run it again the numbers are all wrong. TIA. -gk- |
Resetting variables
Ah, I believe I have a variable scope issue then. All my variables are
declared at the module level. Perhaps I need to move some of the declarations inside the appropriate procedure? -gk- "Rocky McKinley" wrote in message ... If your variables are delcared with Dim in the sub then they should reset when the routine ends. If you declare them with Static then they will retain there values between calls. If your variables are delcared as Public at the top of a module they will retain their values after code has ended and other procedures can see the Public variable values also. Variables declared using the Public statement are available to all procedures in all modules in all applications unless Option Private Module is in effect; in which case, the variables are public only within the project in which they reside. -- Regards, Rocky McKinley "TBA" wrote in message ... Is there a way to reset all variables in a macro? When I run it the first time my results match my control results perfectly, but when I run it again the numbers are all wrong. TIA. -gk- |
All times are GMT +1. The time now is 10:23 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com