我知道这段代码可以很容易地重写为使用循环,但我不能。
k1 = (exk - 3 * increment)
k2 = k1 + 0.01
k3 = k2 + 0.01
k4 = k3 + 0.01
k5 = k4 + 0.01
k6 = k5 + 0.01
k7 = k6 + 0.01
Cells(7, 2).Value = k1
Cells(8, 2).Value = k2
Cells(9, 2).Value = k3
Cells(10, 2).Value = k4
Cells(11, 2).Value = k5
Cells(12, 2).Value = k6
Cells(13, 2).Value = k7
最佳答案
给你:
Sub Rewrite_Code()
Dim k() As Double
Dim i As Integer
Const x = 7
ReDim k(x)
k1 = (exk - 3 * increment)
'Redim Preserve k(i+1) '(this can using when program situation interactively changes)
For i = 1 To x
k(i + 1) = k(i) + 0.01
ActiveSheet.Cells(i + 6, 2).Value = k(i)
Next i
End Sub 'Rewrite
关于vba - 无法理解如何在 Excel VBA 中使用 for...next 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46466598/