Setting "Const" equal to a cell reference in VBA

carstenp

Board Regular
Joined
May 27, 2010
Messages
148
Howdy,

I have a setup where I've written several functions referencing variables that I have hardcoded in
Code:
Const SmallDP As Double = 6.5
but I'd like to set up something like this
Code:
Dim SmallDP As Double
SmallDP = Thisworkbook.worksheets("Input").cells(15,8)
Is there a way to do this without running a subroutine?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Not sure I understand what you mean by w/o running a subroutine. You can use the Dim statement you posted directly in a function.
 
Upvote 0
I think what you are trying to do is to set a global variable through the VBA compiler using an Excel sheet value.

As far as I know, this is not possible and if there is some solution out there it would be very wonky indeed.
That being said, what is the purpose of setting a CONST or global variable if you don't want to run a SUB/FUNCTION to use it.

Perhaps some more detail might clarify the situtation.
 
Upvote 0
I think what you are trying to do is to set a global variable through the VBA compiler using an Excel sheet value.

As far as I know, this is not possible and if there is some solution out there it would be very wonky indeed.
That being said, what is the purpose of setting a CONST or global variable if you don't want to run a SUB/FUNCTION to use it.

Perhaps some more detail might clarify the situtation.

That is what I was trying to do. I've got over 100 custom functions that reference the constants and rather than either hardcoding them in VBA every time they change or adding another variable in the equation where I link to cell H15 on the input page I thought I could just set VBA to pull from there, but it doesn't sound like that's possible. Thanks for the responses
 
Upvote 0
You could use named ranges to contain the values and just reference them in your code
 
Upvote 0

Forum statistics

Threads
1,207,111
Messages
6,076,607
Members
446,216
Latest member
BEEALTAIR

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