Assigning values to constant from userform in VBA

ashvn

New Member
Joined
Jul 2, 2015
Messages
1
I would like my code to take a value from textbox in the userform and use it as a constant for declaring values to other function for eg

Const i1max=userform1.textbox1.value

dim sys(1 to i1max) as computertype

I am getting a compilation error stating that constnt variable should be defined explicitly.

Is there any possible solution to overcome this problem
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Remove the Option Explicit statement from your code or set a default value for your constant then let it vary using the textbox.
When you use the Option Explicit statement, you must explicitly declare all variables using the Dim, Private, Public, or ReDim statements. If you attempt to use an undeclared variable name, an error occurs
 
Upvote 0
Hi,

A constant by definition has to be just that so AFAIK there's no way to declare a constant in that way or by using a cell value.
 
Upvote 0
It needs to be a constant value, not something that can change.

expression
Literal, other constant, or any combination that includes all arithmetic or logical operators except Is
You can't use variables, user-defined functions, or intrinsic Visual Basic functions (such as Chr) in expressions assigned to constants.
 
Upvote 0

Forum statistics

Threads
1,223,264
Messages
6,171,081
Members
452,377
Latest member
bradfordsam

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