[英]Dropping out of a Do or For Loop- not working for me
I am attempting to mark rows based on criteria, by putting a value in a column. 我试图通过将值放在列中来基于条件标记行。 In columns a thru f, about 35,000 rows, I have my data.
在第3列至第35,000行中,我有我的数据。 In columns i thru j, only 51 rows, I have my criteria.
在第i列至第j列中,只有51行,我有我的标准。 Column b is empty and I want to fill it with either "KEEP" or "DELETE" based if columns c and f, meet the criteria in columns i and j.
b列为空,如果c和f列满足i和j列的条件,则我想用“ KEEP”或“ DELETE”填充它。 Once I hit a "KEEP" value, I want the inner loop to stop and continue with the outer loop.
达到“ KEEP”值后,我希望内循环停止并继续外循环。 I don't really know exactly what I'm doing (obviously).
我真的不知道我在做什么(显然)。 I would appreciate some help from someone who does.
我将不胜感激。 Thank you!
谢谢!
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
Change: 更改:
If (Z = "KEEP") Then Exit For
to: 至:
Exit do
EDIT 编辑
Put your check in front. 把支票放在前面。
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
Because the correct way is : 因为正确的方法是:
Do Until row >= 33600
'......
Loop
With a for 与一个
for row = 2 to 33600
'...
If (Z = "KEEP") Then
Exit For
Else
'...
next row
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.