这是我的代码:
Sub Horizon()
Dim i As Double, j As Double, x As Double, y As Double
Sheets("B").Range("C3:G10000").ClearContents
x = InputBox("Number of rows in A")
y = InputBox("Number of rows in B")
For i = 3 To x
For j = 3 To y
If Sheets("B").Cells(j, 1) = Sheets("A").Cells(i, 1) And Sheets("B").Cells(j, 2) >= Sheets("A").Cells(i, 2) And Sheets("B").Cells(j, 2) <= Sheets("A").Cells(i, 3) Then
Sheets("B").Cells(j, 3) = Sheets("A").Cells(i, 4)
Sheets("B").Cells(j, 4) = Sheets("A").Cells(i, 5)
Sheets("B").Cells(j, 5) = Sheets("A").Cells(i, 6)
Sheets("B").Cells(j, 6) = Sheets("A").Cells(i, 7)
Sheets("B").Cells(j, 7) = Sheets("A").Cells(i, 8)
Else
Exit For
End If
Next j
Next i
End Sub
Next i
之前Next j
和exit for
怎么办?{有没有办法?
我尝试过这种方式i=i+1
,但它没有用。如果我在next i
之前写next j
和exit for
,那就会给我一个错误。
答案 0 :(得分:-1)
这个快速测试:显示&#34; 8&#34;在输出..所以不知道为什么你说i = i + 1不起作用?它&#34;应该&#34;。 ;)
Sub test()
For i = 1 To 10
If i = 5 Then Exit For
Next i
i = i + 3
MsgBox (i)
End Sub
[编辑]啊,刚刚注意到,你说&#34;之前&#34;退出...嗯,这更有趣...... [/ edit]
[/ edit2]或不...只是尝试过..对我有用
Sub test()
For i = 1 To 10
If i = 5 Then
i = i + 1
Exit For
End If
Next i
MsgBox (i)
End Sub