我是新手在excel vba中编写代码,我收到编译错误Next Without For .....然而我有一个for和一个下一个,你能告诉我我做错了吗,请看下面的代码,谢谢!
Dim i As Integer
For i = 19 To 49
If Cells(3, i) > 499999 Then
Cells(4, 3) = 499999
ElseIf Cells(3, i) < 499999 Then
Cells(4, 3) = Cells(3, i)
End If
If Cells(4, 3) < 499999 Then
Cells(4, 5) = 0
If Cells(3, i) > 999999 Then
Cells(4, 4) = 500000
ElseIf Cells(3, i) < 999999 Then
Cells(4, 4) = Cells(3, i) - 499999
End If
If Cells(4, 4) = 0 Then
Cells(4, 5) = 0
ElseIf Cells(3, i) > 1999999 Then
Cells(4, 5) = 1000000
ElseIf Cells(3, i) < 1999999 Then
Cells(4, 5) = Cells(3, i) - 999999
End If
If Cells(4, 5) = 0 Then
Cells(4, 6) = 0
ElseIf Cells(3, i) > 4999999 Then
Cells(4, 6) = 3000000
ElseIf Cells(3, i) < 4999999 Then
Cells(4, 6) = Cells(3, i) - 1999999
End If
If Cells(4, 6) = 3000000 Then
Cells(4, 7) = Cells(3, i) - 4999999
ElseIf Cells(4, 6) < 3000000 Then
Cells(4, 7) = 0
End If
Range(7, i).Value = (Cells(5, 3) + Cells(5, 4) + Cells(5, 5) + Cells(5, 6) + Cells(5, 7)) / Cells(3, i)
Next i
End Sub
Run Code Online (Sandbox Code Playgroud)
在第二个If块中,替换
If Cells(4, 3) < 499999 Then
Cells(4, 5) = 0
If Cells(3, i) > 999999 Then
Run Code Online (Sandbox Code Playgroud)
同
If Cells(4, 3) < 499999 Then
Cells(4, 5) = 0
ElseIf Cells(3, i) > 999999 Then
Run Code Online (Sandbox Code Playgroud)
这就是让VBA解释器感到困惑的原因.
| 归档时间: |
|
| 查看次数: |
68 次 |
| 最近记录: |