Supprimer si identique

Bonjour chers tous

Je voudrais supprimer par macro sur mes deux plages les lignes pour lesquelles le Code - l'Age - le sexe sont identiques.

11tri.xlsm (9.06 Ko)

Bonjour,

La présentation sera toujours celle-ci ? Les doublons seront toujours sur la même ligne ?

Si oui le code suivant fait l'affaire :

Sub doublon()
Dim crit1, crit2 As String

For i = Cells(1, 1).End(xlDown).Row To 2 Step -1
crit1 = Cells(i, 1) & Cells(i, 3) & Cells(i, 4)
crit2 = Cells(i, 7) & Cells(i, 9) & Cells(i, 10)
If crit1 = crit2 Then Rows(i & ":" & i).EntireRow.Delete
Next
End Sub

Bonjour

Bonjour à tous

Un essai à tester. Te convient-il ?

12tri-v1.xlsm (23.66 Ko)

Bye !

Hello Gmb,

Merci pour le partage de ta version !

Ca fait un petit moment que je vois bien qu'il faudrait que je passe plus souvent par les tableaux en mémoire, sans toujours y parvenir !

Pourrais-tu, s'il te plaît, commenter un peu tout ceci ? J'ai du mal à voir notamment à quoi sert k ici.

Par avance merci !

@JoyeuxNoel

Le même essai avec macro commentée.

10tri-v1-b.xlsm (25.55 Ko)

Bye !

Waouh, merci beaucoup pour le partage !

J'y vois un peu plus clair (la digestion entière prendra un peu de temps quand même )

Mais du coup, je vois souvent que tu boucles de 1 à 5, comme ici

For j = 1 To 5

D'où vient ce 5 ?

Salut KTM,
Salut l'équipe,

juste histoire de plonger Père Noël dans un abîme de réflexion...
Un double-clic sur la feuille démarre la macro.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'
Dim tTab, iRow%, iCol1%, iCol2%
'
Cancel = True
iRow = UsedRange.Rows.Count
tTab = Range("A2:K" & iRow).Value
iCol1 = IIf(Range("A" & Rows.Count).End(xlUp).Row >= Range("G" & Rows.Count).End(xlUp).Row, 1, 7)
iCol2 = IIf(iCol1 = 1, 7, 1)
Range("A2:K" & iRow - 1).Value = ""
'
For x = 1 To UBound(tTab, 1)
    For y = 1 To UBound(tTab, 1)
        If tTab(x, iCol1) = tTab(y, iCol2) And CInt(tTab(x, iCol1 + 2)) = CInt(tTab(y, iCol2 + 2)) And tTab(x, iCol1 + 3) = tTab(y, iCol2 + 3) Then _
            tTab(x, iCol1 + 1) = 0: _
            tTab(x, iCol2 + 1) = 0
    Next
Next
For x = 1 To UBound(tTab, 1)
    iOK = 0
    If tTab(x, iCol1 + 1) = 0 Then iOK = 1
    If tTab(x, iCol2 + 1) = 0 Then iOK = IIf(iOK = 0, 3, 2)
    For y = 0 To 4
        tTab(x, iCol1 + y) = IIf(iOK > 0 And iOK < 3, "", tTab(x, iCol1 + y))
        tTab(x, iCol2 + y) = IIf(iOK > 0, "", tTab(x, iCol2 + y))
    Next
Next
Range("A2").Resize(UBound(tTab, 1), UBound(tTab, 2)).Value = tTab
Range("A1:E" & Range("A" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeBlanks).Delete shift:=xlUp
Range("G1:K" & Range("G" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeBlanks).Delete shift:=xlUp
'
End Sub


A+

6tri-v1-b.xlsm (19.13 Ko)

Merci Curluris ;)

Effectivement, tu me plonges en pleine réflexion. A-t-on besoin de ça ?

iCol1 = IIf(Range("A" & Rows.Count).End(xlUp).Row >= Range("G" & Rows.Count).End(xlUp).Row, 1, 7)
iCol2 = IIf(iCol1 = 1, 7, 1)

On peut juste prendre les données de la colonne A, non? À partir du moment où il n'y a plus de données en A, il ne peut de facto pas y avoir de doublon en G ? (ou je me fourvoie quant à l'utilité de ce bout de code ?)

Question subsidiaire : Pourquoi sinon 7 ?

Salut Joyeux Noël,

mais, tu as tout à fait raison, mon ami...

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'
Dim tTab, iRow%
'
Cancel = True
iRow = UsedRange.Rows.Count
tTab = Range("A2:K" & iRow).Value
Range("A2:K" & iRow - 1).Value = ""
'
For x = 1 To UBound(tTab, 1)
    For y = 1 To UBound(tTab, 1)
        If tTab(x, 1) = tTab(y, 7) And CInt(tTab(x, 3)) = CInt(tTab(y, 9)) And tTab(x, 4) = tTab(y, 10) Then _
            tTab(x, 2) = 0: _
            tTab(x, 8) = 0
    Next
Next
For x = 1 To UBound(tTab, 1)
    iOK = 0
    If tTab(x, 2) = 0 Then iOK = 1
    If tTab(x, 8) = 0 Then iOK = IIf(iOK = 0, 3, 2)
    For y = 0 To 4
        tTab(x, 1 + y) = IIf(iOK > 0 And iOK < 3, "", tTab(x, 1 + y))
        tTab(x, 7 + y) = IIf(iOK > 0, "", tTab(x, 7 + y))
    Next
Next
Range("A2").Resize(UBound(tTab, 1), UBound(tTab, 2)).Value = tTab
Range("A1:E" & Range("A" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeBlanks).Delete shift:=xlUp
Range("G1:K" & Range("G" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeBlanks).Delete shift:=xlUp
'
End Sub


A+

@ Joyeux Noël

pourquoi 7 ?
Ayant "flashé" le tableau [A2:K xx] dans un tableau tTab unique, 7 représent...ait la colonne [G:G].

Mais, tu es passé par là et tu as bousillé tout mon bel échafaudage!


A+

Eheh, merci !

Grâce au 7 de Curulis, j'imagine maintenant à quoi correspond le 5 !

Du coup, nouvelle question :

    For i = 2 To UBound(tablo1, 1)
        dico1(tablo1(i, 1) & tablo1(i, 3) & tablo1(i, 4)) = ""

pourquoi = vide ?

Bonjour à tous

JoyeuxNoel a écrit :

For j = 1 To 5

D'où vient ce 5 ?

Il vient du nombre de colonnes des 2 tableaux.

OK ?

Bye !

Bonjour,

Et de nouveau un multiposte.

8 personnes au total sur ce sujet sur 2 différents forums.

Cdlt.

Rechercher des sujets similaires à "supprimer identique"