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
|
Sub essai()
Set champ = Range("e3:f100")
For Each c In [A4:A8]
c.Offset(, 1) = MotPlusFrequent(champ, c)
c.Offset(, 2) = MotPlusFrequent2(champ, c)
Next c
End Sub
Function MotPlusFrequent(champ, critère)
Set MonDico = CreateObject("Scripting.Dictionary")
a = champ
For i = LBound(a) To UBound(a)
If a(i, 1) = critère Then MonDico(a(i, 2)) = MonDico(a(i, 2)) + 1
Next i
m = 0
For Each c In MonDico
If MonDico.Item(c) > m Then m = MonDico.Item(c): temp = c
Next c
MotPlusFrequent = m
End Function
Function MotPlusFrequent2(champ, critère)
Set MonDico = CreateObject("Scripting.Dictionary")
a = champ
For i = LBound(a) To UBound(a)
If a(i, 1) = critère Then MonDico(a(i, 2)) = MonDico(a(i, 2)) + 1
Next i
m = 0
For Each c In MonDico
If MonDico.Item(c) > m Then m = MonDico.Item(c): temp = c
Next c
m2 = 0
For Each c In MonDico
If c <> temp Then
If MonDico.Item(c) > m2 Then m2 = MonDico.Item(c): temp2 = c
End If
Next c
MotPlusFrequent2 = m2
End Function |
Partager