Détecter chevauchement de date après concaténation VBA

Bonjour à toutes et tous,

Je suis novice en VBA, j'ai besoin d'aide svp. J'ai un fichier excel dans lequel j'enregistre le paramètrage de mes produits. On trouve la "clé" d'un produit en faisant la concaténation de certaines colonnes. Je souhaite savoir si j'ai paramétré deux fois un même produit dans un même intervalle de date qui fera que je le paierai deux fois au lieu d'une. J'ai un code VBA qui m'a permis de trouver des chevauchements de date et qui marche car il m'a trouvé les bons doublons, le voici :

Cependant lorsque que je l'applique à un autre fichier excel et que je veux prendre les colonnes A, C, E (au lieu de A, C, D dans le code), je change la lettre E partout au à la place du D, mais il m'affiche des résultats faux et incohérents. Donc je ne sais pas si c'est un coup de chance qu'il m'ai détecté les bons doublons la première fois..

Merci de m'avoir lu.
Cordialement,

Sub Chev1()

Dim ColA As Integer
ColA = Range("A" & Rows.Count).End(xlUp).Row
Dim ColC As Integer
ColC = Range("C" & Rows.Count).End(xlUp).Row
Dim ColD As Integer
ColD = Range("D" & Rows.Count).End(xlUp).Row

Dim tableau(1000) As String
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False

 If ColA >= ColC And ColA >= ColD Then

For i = 2 To Cells(Rows.Count, "B").End(xlUp).Row
    tableau(i) = Cells(i, "A").Value & Cells(i, "C").Value & Cells(i, "D").Value
Next i

ElseIf ColC >= ColA And ColC >= ColD Then

For i = 2 To Cells(Rows.Count, "C").End(xlUp).Row
    tableau(i) = Cells(i, "A").Value & Cells(i, "C").Value & Cells(i, "D").Value
Next i

Else

For i = 2 To Cells(Rows.Count, "C").End(xlUp).Row
    tableau(i) = Cells(i, "A").Value & Cells(i, "C").Value & Cells(i, "D").Value
Next i

End If

For i = 1 To 1000
    'Cells(i, "A").Interior.Color = RGB(255, 255, 255)
    'Cells(i, "C").Interior.Color = RGB(255, 255, 255)
    'Cells(i, "D").Interior.Color = RGB(255, 255, 255)
    Rows.Interior.Color = RGB(255, 255, 255)

Next i

Dim Cpt As Integer
Cpt = 0
For i = 1 To 1000
    For j = 1 To 1000
        If i <> j Then
            If tableau(i) = tableau(j) And tableau(i) <> "" Then
                'Cells(i, "A").Interior.Color = RGB(255, 0, 0)
                'Cells(i, "C").Interior.Color = RGB(255, 0, 0)
                'Cells(i, "D").Interior.Color = RGB(255, 0, 0)
                Rows(i).Interior.Color = RGB(255, 0, 0)
                Cpt = Cpt + 1
            End If
        End If
    Next j
Next i

If Cpt > 0 Then
    MsgBox (Cpt / 2 & " doublons")
Else
    MsgBox ("Aucun doublons")
End If
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.Calculate
End Sub

Bonsoir

avec un fichier on y verrait plus clair

Rechercher des sujets similaires à "detecter chevauchement date concatenation vba"