SuperQuick Q: Constants...?

ClimoC

Well-known Member
Joined
Aug 21, 2009
Messages
584
So a Const/#Const only work as Private compiler constants... ie, for the module within which they reside.

Can I have a Public compiler constant at all?

Essentially, before every script in my 20 modules and forms runs, I want it to obtain the value from Sheet3, Cell E2

I would've thought #Const SecLvl = Sheets("GridData").Range("E2").Value or a variation thereof would work, but apparently not. Unrecognised, invalid, wrong syntax, you name it, I've gotten an error for it.

Any help as to how I can do this? Or do I have to Global my integer and then set the value at runtime with a line like 'SecLvl = Sheets("GridData").Range("E2").Value' etc

Thanks
C
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
If you assign a value to a Constant based on a worksheet cell it's not really a constant. So you are correct that an alternative would be to use a Global variable and assign at runtime.
 
Upvote 0
Thanks FireFly.

I sort of figured as much, as the two ideas do sort of contradict each other - but had just wondered if a variable could at least be declared as always Cell E2 of sheet 3 etc...

S'only one extra line of code... heck... the book has 10,000....
 
Upvote 0

Forum statistics

Threads
1,215,024
Messages
6,122,729
Members
449,093
Latest member
Mnur

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top