4

my array size is decided by the some other function. but when i tried to define the size of the array using the variable i am getting the error "Constant Expression Required"

i would like define the size of the array

Option Explicit
Sub Abcd()
    Dim n_variables As Integer
    n_variables = def()
    MsgBox "n_variables" & n_variables
    Dim abc(1 To n_variables) As Integer  
End Sub
Function def()
    def = 100
End Function

is there any way i can define the array size in variable format? Any one help me please.

1
  • 1
    You can always use Redim to change array size. Commented Apr 25, 2016 at 9:06

1 Answer 1

4

Use the Redim statement:

Dim n_variables As Integer
n_variables = def()
MsgBox "n_variables" & n_variables
Dim abc() As Integer  
Redim abc(1 To n_variables) As Integer
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.