Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default 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-


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Resetting variables

The End statement immediately clears all variables (and terminates macro
execution).

--
Jim Rech
Excel MVP


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default 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-




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default 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-






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
Resetting Defaults jnix Setting up and Configuration of Excel 1 August 12th 09 10:29 PM
Resetting cells Chuck Excel Worksheet Functions 1 December 17th 07 06:45 PM
Why are my options resetting themselves? cbare Excel Discussion (Misc queries) 0 November 2nd 06 11:30 PM
password resetting Mohan Kumar Excel Discussion (Misc queries) 1 September 3rd 06 03:38 AM
Resetting the end of a worksheet Cachod1 New Users to Excel 1 March 29th 05 07:44 PM


All times are GMT +1. The time now is 03:18 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"