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.
To run my example you will need to fill columns A and B in Sheet1 with some values. Then run test(). It will read first two rows and add the values to the BigArr. Then it will check how many rows of data you have and read them all, from the place it has stopped reading, i.e., 3rd row.
From the View menu, choose Immediate window (CTRL+G).
To print a multi-dimensional array, you instead need to call the Arrays. deepToString() method and pass the multi-dimensional array as an argument.
If this is for debugging purposes, it's not convenient to write a macro to view the contents of the array during program execution. Might even cause problems.
For debugging during program execution, you'll want a code-free method you can use across all VB projects, to spy the contents of your array.
In this example, "aLookList" is a variant array. The values under "Value2" come from a range.
Another answer here suggests using the Watch pane. This is similar to my answer, but poster did not explain that you can spy the entire array (all cells) by simply adding the array name to Watch. Then , drill down nodes. The advantage of the Locals Window over the Watch Window, is that with Locals pane, you do not have to manually add the array to the pane, it's already there. So it's a bit less effort.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With