我有一个问题,我无法解决。 我需要找出一个产品是否存在,所以它不应该被处理两次(或更多)。这是我的代码:
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
这里,当我调试时,我看到(i,2)值永远不会设置为1,所以我的产品被处理两次。我只是不明白为什么。
感谢您的帮助。
答案 0 :(得分:1)
如果我正确理解您的代码......
行table(i, 2) = 1
位于行If table(i, 2) <> 1 Then
之后,所以如果你设置它并不重要,当它返回到它将循环的If
语句时我将增加,它正在查看下一个值(尚未设置为1)。