tags:

views:

35

answers:

1

Hi there,

I have a problem I just can't fix. I need to find if a product exists so it shouldn't be treated twice (or more). Here's my code :

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

Here, when i debug, i see that the (i, 2) value is never set to 1, so my products are treated twice. I just can't understand why.

Thanks for your helps.

+1  A: 

If I understand your code correctly...

The line table(i, 2) = 1 comes after the line If table(i, 2) <> 1 Then so it doesn't matter if you set it, by the time it comes back to the If statement it'll have looped so that i will have been incremented and it's looking at the next value (that hasn't been set to 1 yet).

ho1
Sorry, my code was incorrect. it was table(j, 2) = 1. Don't know why, but If Not (table(i, 2)) = 1 Then... fixed the problem. Anyway, thanks for taking time to take a look at my code.
Coronier