当我运行此代码时,我得到“运行时错误1004”应用程序定义或对象定义错误。我的搜索没有产生任何结果。
Public Sub problem2()
Dim i As Integer
Dim num(1 To 40) As Long
Dim sum As Long
num(1) = 1
num(2) = 2
Cells(1, 2).Value = num(1)
Cells(2, 2).Value = num(2)
For i = 3 To 40
num(i) = num(i - 1) + num(i - 2)
Cells(i, 2).Value = num(i)
Next i
i = 1
sum = 0
Do While num(i) < 4000000
If Cells(i, 2).Value Mod 2 = 0 Then sum = sum + num(i)
i = i + 1
Loop
Range(A1).Value = sum
End Sub