辍学的做或For循环 – 不为我工作

我试图通过在列中添加一个值来根据条件标记行。 在大约35,000行的列中,我有我的数据。 在我通过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