Search code examples
arraysvbaimmediate-window

How to print two dimensional array in Immediate window in VBA?


How to print two dimensional array in Immediate window in VBA ? Does it exist any generic method for doing this ? Some method for ploting one row of array per line in Immediate window could solve this problem, because then only thing to do is to loop this code for each line of array.


Solution

  • I made a simple loop to do this for anybody's reference:

    Sub WriteArrayToImmediateWindow(arrSubA As Variant)
    
    Dim rowString As String
    Dim iSubA As Long
    Dim jSubA As Long
    
    rowString = ""
    
    Debug.Print
    Debug.Print
    Debug.Print "The array is: "
    For iSubA = 1 To UBound(arrSubA, 1)
        rowString = arrSubA(iSubA, 1)
        For jSubA = 2 To UBound(arrSubA, 2)
            rowString = rowString & "," & arrSubA(iSubA, jSubA)
        Next jSubA
        Debug.Print rowString
    Next iSubA
    
    End Sub