ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   keep variable value after code quits (https://www.excelbanter.com/excel-discussion-misc-queries/236095-keep-variable-value-after-code-quits.html)

Steve

keep variable value after code quits
 
If I have code that prompts the user for some sort of input, is it possible
to have store the value of the variable so the next time the macro runs, it's
available?

Bob Phillips[_3_]

keep variable value after code quits
 
As long as next time is still within the same Excel session, create a public
variable and store it there.

--
__________________________________
HTH

Bob

"Steve" wrote in message
...
If I have code that prompts the user for some sort of input, is it
possible
to have store the value of the variable so the next time the macro runs,
it's
available?




Don Guillett

keep variable value after code quits
 
Store it in a public variable, or, if you want it the next time you open, a
cell

public savethis
sub()
ddd
savethis="OK"
end sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Steve" wrote in message
...
If I have code that prompts the user for some sort of input, is it
possible
to have store the value of the variable so the next time the macro runs,
it's
available?



Luke M

keep variable value after code quits
 
If its a continuous segment of code, or one macro jumping to another yes.
Otherwise, I'd have the code write the value to a cell somewhere, and then
refer to that cell. (maybe do an if blank check or something)
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"Steve" wrote:

If I have code that prompts the user for some sort of input, is it possible
to have store the value of the variable so the next time the macro runs, it's
available?


Jacob Skaria

keep variable value after code quits
 
Steve

Refer the below link to get a better understand of variables and scope.
http://www.ozgrid.com/VBA/variable-scope-lifetime.htm

If this post helps click Yes
---------------
Jacob Skaria


"Steve" wrote:

If I have code that prompts the user for some sort of input, is it possible
to have store the value of the variable so the next time the macro runs, it's
available?



All times are GMT +1. The time now is 05:33 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com