[英]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.