ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   storing a value in code (https://www.excelbanter.com/excel-programming/360859-storing-value-code.html)

Giselle[_2_]

storing a value in code
 

NEWBIE question:

I run code that retrieves an integer value 'hidden' in a cell on one of my
worksheets. The code uses thus value, then increments it by 1 before
storing the new value back in the 'hidden' cell. Next time I run the code,
it uses the incremented value even if I've closed and reopened the
application. All works well, but....

I'd rather store the value in the code, not in the 'hidden' cell. (so I can
better disallow certain values and manipulate other ones.) How can I store
the value in the code so that it increments as desired but doesn't reset
everytime I open the application?

much thanks
Ginger




Ardus Petus

storing a value in code
 
Use a static variable within your Sub or ont top of your Module
It will retain its current value between calls.

Static lCounter as Long

HTH
--
AP


"Giselle" a écrit dans le message de news:
...

NEWBIE question:

I run code that retrieves an integer value 'hidden' in a cell on one of my
worksheets. The code uses thus value, then increments it by 1 before
storing the new value back in the 'hidden' cell. Next time I run the
code, it uses the incremented value even if I've closed and reopened the
application. All works well, but....

I'd rather store the value in the code, not in the 'hidden' cell. (so I
can better disallow certain values and manipulate other ones.) How can I
store the value in the code so that it increments as desired but doesn't
reset everytime I open the application?

much thanks
Ginger






[email protected]

storing a value in code
 
The key to this question is that you want to store it when the
application isn't running - and you cannot do this - at least, not
without it physically being somewhere - a hidden cell would be one
solution, using an INI file or the registry is another solution.


Lucas Swanson

storing a value in code
 
He could have a special sheet for storing any values like this that he needs,
& write code to create this sheet before the workbook closes, & retrieve the
information then delete/hide the sheet when the workbook opens.

" wrote:

The key to this question is that you want to store it when the
application isn't running - and you cannot do this - at least, not
without it physically being somewhere - a hidden cell would be one
solution, using an INI file or the registry is another solution.



[email protected]

storing a value in code
 
Agreed, but the original post implied not wanting to do this - although
I agree that rather than a hidden cell, I would have an entire hidden
sheet! Never needs to be unhidden as the code can reference it anyway



All times are GMT +1. The time now is 12:09 AM.

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