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
| Option Explicit
Sub Semblables()
Dim kr1 As Long, kr2 As Long, kC1 As Long, kC2 As Long
Dim kR As Long, kRfin As Long
Dim v As Variant, nIdem As Integer, r As Range
Dim wshRes As Worksheet
Worksheets("Data").Select
kRfin = Cells(Rows.Count, 3).End(xlUp).Row '--- n° dernière ligne en colonne 3 (T°)
Set wshRes = Worksheets("Résultat")
wshRes.Cells.ClearContents
For kr1 = 5 To kRfin - 1 '--- de éch.1 à l'avant-dernier éch.
wshRes.Cells(kr1, 1) = Cells(kr1, 1)
wshRes.Cells(4, kr1 - 3) = Cells(kr1, 1)
wshRes.Cells(kr1, kr1 - 3) = "#"
For kr2 = kr1 + 1 To kRfin '--- de éch. suivant au dernier éch.
nIdem = 0
For kC1 = 4 To 33 '--- de test 1 (colonne 4) à test 20 (colonne 33)
v = Cells(kr1, kC1)
If v <> "" Then
kC2 = Int((kC1 - 4) / 5) * 5 + 4
nIdem = nIdem + WorksheetFunction.CountIf(Range(Cells(kr2, kC2), Cells(kr2, kC2 + 4)), v)
'Debug.Print kR1, kC1, v, kR2, kC2, nIdem, Range(Cells(kR2, kC2), Cells(kR2, kC2 + 4)).Address
End If
Next kC1
'Debug.Print "---"
DoEvents
wshRes.Cells(kr1, kr2 - 3) = nIdem
Next kr2
Next kr1
wshRes.Cells(kr1, 1) = Cells(kr1, 1)
wshRes.Cells(4, kr1 - 3) = Cells(kr1, 1)
wshRes.Cells(kr1, kr1 - 3) = "#"
Worksheets("Résultat").Select
Range("C5").Select
End Sub |