Define an array with variable size

  • Thread starter Thread starter Yiu Choi Fan
  • Start date Start date
Y

Yiu Choi Fan

Hi all,

In my Excel VBA program, I have to define an array, but the dimension of
this array is a variable, which dependents on the value in cell B1. I think
this is an easy problem but I don't know how to solve it >_<

Thanks very much for your help!!

Best wishes
C.F. Yiu
 
Hi Choi Fan,

Sub Test()
Dim Arr() As Variant
Dim i As Long

i = Range("A1").Value
ReDim Arr(1 To i)

End Sub
 
Choi Fan,

Option Explicit
Sub ArrayDimension()
Dim vArray As Variant
ReDim vArray(0 To Sheets(1).Range("A1").Value)
MsgBox UBound(vArray, 1)
End Sub

The traffic is hell in Central if you are trying to get home that way. Just
took me 25 minutes to get past the Convention Centre from the Star Ferry.

Robin Hammond
www.enhanceddatasystems.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top