REDIM preserve给“下标越界” [英] Redim Preserve gives 'subscript out of range'
问题描述
我想 REDIM preserve
数组我不断收到错误下标超出范围。我知道的事实,即只有最后一维的尺寸可以改变。这就是我在做什么。这是怎么回事错在这里?该类型的数组是变
。
BmMatrix =表(冷板凳),范围(A60,ActiveSheet.Range(A60)。完(xlDown).END(xlToRight))
每subdeelTOTAAL gewicht数组wegschrijven
昏暗aBmMatrix()
aBmMatrix = BmMatrix
RIJ = UBound函数(BmMatrix,1)
KOL = UBound函数(BmMatrix,2)+1
使用ReDim preserve aBmMatrix(RIJ,KOL)
TotGewKol = UBound函数(aBmMatrix,2)
对于i = 2到UBound函数(BmMatrix,1)
G = 0'G wordt TOTAAL gewicht面包车土地BV
如果BmMatrix(I,bm_kolom)LT;> X然后
对于j = 2至UBound函数(bmexnul,1)
如果bmexnul(J,weightkolom)= BmMatrix(I,bm_kolom)则G = G + bmexnul(J,10)
下面j
万一
aBmMatrix(I,TotGewKol)= G
aBmMatrix(1,TotGewKol)=TOTAAL gewicht'性标题kolom
接下来,我
由于您指定 aBmMatrix
使用数组的值
一系列属性,返回的数组 1
的下限为每个维度。
当您以后REDIM它没有明确提供下界时,REDIM尝试为每个维度的默认下界,这是 0
。
您需要显式提供下界:
使用ReDim preserve aBmMatrix(LBOUND(aBmMatrix,1)RIJ,LBOUND(aBmMatrix; 2)KOL)
I want to Redim Preserve
an array I keep getting the error 'subscript out of range'. I am aware of the fact that only the size of the last dimension can be changed. That is exactly what I am doing. What is going wrong over here? The type of the array is 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
Because you assign aBmMatrix
array using the Value
property of a range, the returned array has lower bounds of 1
for each dimension.
When you later redim it without providing lower bounds explicitly, the redim tries to assign each dimension the default lower bound, which is 0
.
You need to explicitly provide the lower bounds:
ReDim Preserve aBmMatrix(lbound(aBmMatrix,1) to rij, lbound(aBmMatrix,2) to kol)
这篇关于REDIM preserve给“下标越界”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!