[英]Dropping out of a Do or For Loop- not working for me
我试图通过将值放在列中来基于条件标记行。 在第3列至第35,000行中,我有我的数据。 在第i列至第j列中,只有51行,我有我的标准。 b列为空,如果c和f列满足i和j列的条件,则我想用“ KEEP”或“ DELETE”填充它。 达到“ KEEP”值后,我希望内循环停止并继续外循环。 我真的不知道我在做什么(显然)。 我将不胜感激。 谢谢!
Sub test()
Dim row As Integer
Dim row2 As Integer
Dim col As Integer
Dim col2 As Integer
Dim col3 As Integer
Dim col4 As Integer
Dim col5 As Integer
Dim x As String
Dim y As String
Dim a As String
Dim b As String
row = 2
row2 = 2
col5 = 2
Do
col = 3
col2 = 6
col3 = 9
col4 = 10
x = Cells(row, col).Value
y = Cells(row, col2).Value
Z = Cells(row, col5).Value
For row2 = 2 To 52
a = Cells(row2, col3).Value
b = Cells(row2, col4).Value
If x = a And y = b Then
Cells(row, col - 1) = "KEEP"
If (Z = "KEEP") Then Exit For
Else
Cells(row, col - 1) = "DELETE"
End If
row2 = row2 + 1
Next
row = row + 1
row2 = 2
Loop Until row >= 33600
End Sub
更改:
If (Z = "KEEP") Then Exit For
至:
Exit do
编辑
把支票放在前面。
For row2 = 2 To 52
if z = "KEEP" then
Exit for
else
a = Cells(row2, col3).Value
b = Cells(row2, col4).Value
If x = a And y = b Then
Cells(row, col - 1) = "KEEP"
Exit For
Else
Cells(row, col - 1) = "DELETE"
End If
row2 = row2 + 1
end if
Next
因为正确的方法是:
Do Until row >= 33600
'......
Loop
与一个
for row = 2 to 33600
'...
If (Z = "KEEP") Then
Exit For
Else
'...
next row
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.