2

I want to create a Sub in vba that has an Array as parameter. The following code works:

Sub phase1State(ByRef arr() As String) 

Now, I want that parameter to be an array of arrays, or jagged array, how can I do that?

Thanks!

1
  • 2
    Magic word here is variant. A variant Array can store and Array. And can be passed as param Commented Apr 29, 2016 at 10:39

2 Answers 2

4
Sub test()
    Dim jagged As Variant
    ReDim jagged(1 To 3)
    jagged(1) = Array(1, 2, 3)
    jagged(2) = Array(4, 5, 6)
    jagged(3) = Array(7, 8, 9)
    phase1State jagged
End Sub

Sub phase1State(ByRef arrJagged As Variant)
    Debug.Print arrJagged(2)(2) ' 6
End Sub
Sign up to request clarification or add additional context in comments.

Comments

1
Sub Arraycheck()
    ReDim Arr(3) As String
    Arr(1) = "1"
    Arr(2) = "2"
    Arr(3) = "3"
    Call parameter(Arr())
End Sub
Sub parameter(getarr() As String)
    Debug.Print getarr(2)
End Sub

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.