1

I don't know how to create a dynamic multidimensional Array. At present i have declared my array as Dim fArr(0 To 4, 0 To 9). it is always (0 to 4) in one dimension but other dimension (0-9) is always variable so how do i do it?.

I populate my array like this example

     Select Case fTyp
         Case Is = "A"
             fArr(0, aRow) = j
         Case Is = "B"
             fArr(1, aRow) = j
         Case Is = "C"
             fArr(2, aRow) = j
     End Select

Thanks

4
  • 2
    What is the second dimension dependent on? Commented Oct 28, 2015 at 18:54
  • 1
    Possible duplicate of Dynamic Multi-Dimensional array problem Commented Oct 28, 2015 at 19:49
  • just before your loop redim farr(4,x) as variant x is the variable that you use in your for loop for arow = 0 to x. so what ever you have in place of x in your for loop put that same thing in for x in the redim. Just like @AlexWeber stated. Commented Oct 28, 2015 at 20:03
  • 1
    Just an unrelated side note, wouldn't Case "A" be simpler than Case Is = "A"? Commented Oct 28, 2015 at 21:33

1 Answer 1

3

You can use a ReDim to create a dynamic amount of dimensions in an array. Firstly, you must dim your array in the following way:

Dim fArr() as String ' Or whatever datatype you want

Then, when you're ready to enter the dimension of the Array, you use a ReDim.

ReDim fArr(4, VBAVariable) as String 'Or whatever datatype you want

You can ReDim multiple times. Check out this article for extra features that ReDim has.

Sign up to request clarification or add additional context in comments.

1 Comment

at present it is like this

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.