我想要超出范围的一个数组,我一直得到‘Redim Preserve of range’的错误。我知道只有最后一个维度的大小是可以改变的。这正是我正在做的。这里出了什么问题?数组的类型为Variant。
BmMatrix = Sheets("BENCH").Range("a60", ActiveSheet.Range("a60").End(xlDown).End(xlToRight))
'totaal gewicht per subdeel in array wegschrijven
Dim aBmMatrix()
aBmMatrix = BmMatrix
rij = UBound(BmMatrix, 1)
kol = UBound(BmMatrix, 2) + 1
ReDim Preserve aBmMatrix(rij, kol)
TotGewKol = UBound(aBmMatrix, 2)
For i = 2 To UBound(BmMatrix, 1)
g = 0 'g wordt totaal gewicht van land bv
If BmMatrix(i, bm_kolom) <> "x" Then
For j = 2 To UBound(bmexnul, 1)
If bmexnul(j, weightkolom) = BmMatrix(i, bm_kolom) Then g = g + bmexnul(j, 10)
Next j
End If
aBmMatrix(i, TotGewKol) = g
aBmMatrix(1, TotGewKol) = "Totaal gewicht" 'titel kolom
Next i发布于 2012-12-27 22:04:06
由于使用范围的Value属性为aBmMatrix数组赋值,因此返回的数组具有每个维度的1下限。
当您稍后在没有显式提供下限的情况下对其进行redim时,redim会尝试为每个维度分配默认的下限,即0。
您需要显式地提供下限:
ReDim Preserve aBmMatrix(lbound(aBmMatrix,1) to rij, lbound(aBmMatrix,2) to kol)发布于 2019-04-17 14:05:37
只有在仅更改数组的最后一维时,才能使用保留。
https://stackoverflow.com/questions/14055734
复制相似问题