我有一個問題,我只是無法修復。 我需要找到一個產品是否存在,因此它不應該被處理兩次(或更多)。這裏是我的代碼:VBA:循環找到多餘的值,不要把它處理
Dim table As Variant
finalLig = Cells(Application.Rows.Count, 1).End(xlUp).row
table= Range("C3:D" & finalLig).Value 'two dimensionnal array (nb of products, 2 columns. 2nd column is just here to create a multidimmensionnal array)
For i = LBound(tableau) To UBound(table) 'For all values in the array (barcodes)
If table(i, 2) <> 1 Then
Valeur = table(i, 1) 'Value to check
For J = LBound(tableau) To UBound(tableau) 'Loop in the table
valeurComp = tableau(J, 1)
If Valeur = valeurComp And i <> J Then 'If two lines share the same code, then
table(i, 2) = 1 'remember that this value shouldn't be treated once in the i loop
'my actions here
End If
Next J
End If
Next i
在這裏,當我調試,我看到了(1,2)值永遠不會設置爲1,所以我的產品進行處理,兩次。我只是不明白爲什麼。
感謝您的幫助。
你在表和表之間交換了幾次,但似乎指的是相同的Range對象 – barrowc 2010-09-20 17:26:23