Home > Back-end >  Unfold multidimensional array in local window
Unfold multidimensional array in local window

Time:07-11

I'm debugging my VBA EXCEL macro. I have several multidimensional arrays that I monitor at breakpoints in the local window of the debugger. In the local window, each array is folded and on the right side of the array is a small " " where you can unfold each dimension of the array individually. In my example the dimension is 10 x 3 and I need to click 10 times to unfold the complete array. At the next breakpoints (leaving and entering the subroutine), the array is folded again and I have to click ten times again.

Is there a smarter way to unfold all dimensions of an array or leave the array unfolded?

I've tried: ESC, Enter, Return, , -, *, / and multiple F keys. I tried to mark multiple dimensions but you can only mark one row and not multiple rows of an array.

CodePudding user response:

There's no way of automatically expanding everything in the Locals Window, but if you're doing a lot of debugging and don't have too many arrays that are too large, you can simulate a fully expanded Locals Window using the Watches Window instead.

  • Display the Watches Window through the View menu.
  • Right click on your code to Add Watch... (this can be done even while in Break mode)
  • Add one element of one array at a time.

Demo

It might seem a little tedious, but you can easily add a few dozen elements in less than a minute and they will persist while you have the workbook open (even if you close the VBA editor or run macros in other projects). You can also be more selective about which elements you monitor.

Watches can be any VBA expression, so you could even generate strings that display the arrays in a more compact format:

enter image description here

If you need to reinstate watches regularly, there's a clunky option for adding them automatically: How can I save VBA watches manually or add them via code?

  • Related