Permanent Variable?

  • Thread starter Thread starter Random
  • Start date Start date
R

Random

I am sure this is a pretty stupid question, but.....

Is there any way to store a permanent variable that can be incremented
over time between sessions and calls to the function? Meaning: I want
to store a number in a variable that can be accessed / added to / and
subtracted from from different functions over the course of many
workbook openings and closings.

For example: perVar would refer to a number like 1.

When function IncPerm() was run, it would add 1 to perVar so that
perVar = 2 for all other functions to reference from then on.

I know that I can store this value in a cell, but I am trying to avoid
that.


Any one have any ideas on this? All help is greatly appreciated.

Many thanks,

Random
 
Random,

You might consider storing the value in a defined name.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com (e-mail address removed)
 
How would I reference that in VBA? I tried using the macro recorder,
but can't decipher what the verbage is for adding to and subtracting.

I have tried:
ActiveWorkbook.Names("Bob").Value = _
Right(ActiveWorkbook.Names("Bob").Value,
Len(ActiveWorkbook.Names("Bob").Value)-1) + 1

But that errors out....

I can't seem to find this in the help file either... any suggestions?

Random.
 
Create the name ThisName, and give it some initial value. Then use
the following to increment the value:

ThisWorkbook.Names.Add "TheName", _
Val(Mid(ThisWorkbook.Names("TheName").RefersTo, 2)) + 1


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com (e-mail address removed)
 
Back
Top