Reputation:
I've searched all over but am unable to get the answer I am seeking. My question is: Can a variable be used to set the Ubound value in a dynamic array in excel? I have attempted to create a score sheet. The user is prompted for the number of players. I want to use the users response to be the Upper limit of my array. Thank you in advanced for any assistance.
Upvotes: 0
Views: 1574
Reputation: 6654
Yes you can.
First declare the array. and ReDim
it.
Like
Dim arr() as Variant
Dim vari as Integer
'Some code to get the variable.
vari = 10
ReDim Preserve arr(vari)
Preserve
is Used if you do not want to change the Data that is Already there in the Array.
Upvotes: 0
Reputation: 51998
Why not test?
Sub test()
Dim V As Variant
Dim n As Long
n = 10
ReDim V(1 To n)
Debug.Print UBound(V) 'prints 10
End Sub
Upvotes: 1