How can I “ReDim Preserve” a 2D Array in Excel 2007 VBA so that I can add rows, not columns, to the array?

前端 未结 8 1495
梦如初夏
梦如初夏 2020-12-06 02:28

I\'m working with a dynamic array in Excel VBA. The number of columns (m) is fixed, however, I do not know how many rows (n) will be required.

The help documents st

8条回答
  •  离开以前
    2020-12-06 03:05

    No way to determine the number of elements in the first dimension? Bummer. For a two-dimensional array with a fixed second dimension, you might want to consider making it an array of Types ("structs" in other languages) instead. That will allow you to use Redim Preserve, and still leaves you with a reasonable way to add and access values, though you'll now be accessing the second dimension as named members of the Type rather than is index values.

提交回复
热议问题