1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| Option Explicit
Sub test()
Dim xlwbk As Workbook, xlwbs As Worksheet
Dim rng As Range, rngCritere1 As Range, rngCritere2 As Range
Dim dernLigneA As Long, dernLigneDoublon As Long, countLigne As Long, countLigneDoublon As Long, indexLigneA As Long, indexLigneDoublon As Long
Dim i As Long
Dim strDoublon As String, valCritere1 As String, valCritere2 As String
Dim cValeur As Variant
Set xlwbk = ThisWorkbook
Set xlwbs = Worksheets("Feuil1")
dernLigneA = xlwbs.Cells(Rows.Count, 1).End(xlUp).Row
dernLigneDoublon = xlwbs.Cells(Rows.Count, 3).End(xlUp).Row
Set rng = xlwbs.Range(Cells(2, 1), Cells(dernLigneA, 1))
countLigne = 0
indexLigneDoublon = dernLigneDoublon + 1
For Each cValeur In rng.Cells
countLigneDoublon = 0
If InStr(1, strDoublon, "|" & cValeur.Value & "|") = 0 Then
For indexLigneA = 1 To dernLigneA
If rng.Cells(indexLigneA, 1).Value = cValeur.Value Then
countLigneDoublon = countLigneDoublon + 1
End If
Next indexLigneA
If countLigneDoublon > 1 Then
xlwbs.Cells(indexLigneDoublon, 3).Value = cValeur.Value
xlwbs.Cells(indexLigneDoublon, 4).Value = countLigneDoublon
indexLigneDoublon = indexLigneDoublon + 1
strDoublon = strDoublon & "|" & cValeur.Value & "|"
End If
End If
Next cValeur
dernLigneDoublon = Cells(Rows.Count, 3).End(xlUp).Row
Set rngCritere1 = xlwbs.Range(Cells(2, 1), Cells(dernLigneA, 1))
Set rngCritere2 = xlwbs.Range(Cells(2, 2), Cells(dernLigneA, 2))
For i = 2 To dernLigneDoublon
valCritere1 = xlwbs.Range(Cells(i, 3), Cells(i, 3)).Value
valCritere2 = "ok"
xlwbs.Range(Cells(i, 5), Cells(i, 5)) = WorksheetFunction.CountIfs(rngCritere1, "=" & valCritere1, rngCritere2, "=" & valCritere2)
Next i
Set rngCritere2 = Nothing
Set rngCritere1 = Nothing
Set rng = Nothing
Set xlwbs = Nothing
Set xlwbk = Nothing
End Sub |