在VBA Excel中Redim大小的数组

在VBA Excel中使用redim保留函数有一些问题。

我想redim我已经在macros中使用的数组,而不清除已经在里面的数据。

我的macros看起来像这样:

 Dim table_data As Variant ... ReDim table_data(2 * n + 2 * m + 2 * n, table_case.ListColumns.Count - 1) ... dim1 = UBound(table_data, 1) dim2 = UBound(table_data, 2) ReDim Preserve table_data(0 To dim1 + 2 * n, 0 To dim2) 

你有什么想法我应该修改?

使用Preserve关键字时; 您只能更改最后一个尺寸的尺寸。 一旦宣布其他维度的大小必须保持不变。

下面的代码应该工作:

 ReDim Preserve table_data(LBound(table_data, 1) To UBound(table_data, 1), 0 To dim2)