这是代码
Sub logic()
'Declaring variables
Dim r As Long, i As Long, k As Long, l As Long
Dim num() As Long
Dim del() As Long
'Assigning Values
r = 2
i = 0
k = 0
l = 0
ReDim num(0)
ReDim del(0)
Do Until Cells(r, 11).Value = ""
num(i) = Cells(r, 15).Value
'I m getting error over here
del(l) = k - num(i)
k = num(i)
i = i + 1
ReDim Preserve num(i)
'Preserve the value
r = r + 1
l = l + 1
Loop
r = 2
For l = 0 To UBound(num) - 1
Cells(r, 25).Value = del(l)
r = r + 1
Next l
End Sub
答案 0 :(得分:1)
您正在增长num
数组但是您忘记对del
数组执行相同操作。我相信你需要像这样修改代码:
i = i + 1
ReDim Preserve num(i)
'Preserve the value
r = r + 1
l = l + 1
ReDim Preserve del(l) ' Add this line