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
| Option Explicit
Function SommeSpeciale(ByVal Rng As Range, ByVal Mn As Double, ByVal Mx As Double, ByVal ColorInd As Byte) As Long
Dim c As Range
Dim S As Long
For Each c In Rng
If c >= Mn And c <= Mx And c.Interior.ColorIndex = ColorInd Then S = S + 1
Next c
SommeSpeciale = S
End Function
Sub CompteOccurences()
Dim Tb As Range, c As Range
Dim Plage As String
Dim i As Long, LasLg As Integer
Dim Tmp, Rg As Range
Application.ScreenUpdating = False
With Worksheets("Feuil1")
Set Tb = .Range("L2", .Cells(.Rows.Count, "L").End(xlUp))
Tb.Offset(0, -6).ClearContents
Plage = "$A$2:" & .Cells(.Rows.Count, "A").End(xlUp).Address
LasLg = .Cells(.Rows.Count, "A").End(xlUp).Row
Set Rg = .Range("A2:A" & LasLg)
For Each c In Tb
Tmp = Extrema(c)
If IsArray(Tmp) Then
c.Offset(0, -9).Value = c
With c.Offset(0, -8) ' Colonne D
.Formula = "=SUMPRODUCT((" & Plage & ">=" & Tmp(0) & ")*(" & Plage & "<=" & Tmp(1) & ")*1)"
.Value = .Value
c.Offset(0, -7) = SommeSpeciale(Rg, Tmp(0), Tmp(1), 6)
End With
c.Offset(0, -6) = Tmp(0)
End If
Next c
Tb.Offset(0, -9).Resize(, 4).Sort Key1:=Tb.Offset(0, -6).Resize(1, 1), Order1:=xlAscending, Header:=xlNo
Tb.Offset(0, -6).ClearContents
Set Tb = Nothing
End With
End Sub
Private Function Extrema(ByVal Str As String)
Str = Replace(Str, "[", "")
Str = Replace(Str, "]", "")
If InStr(Str, "-") Then Extrema = Split(Str, "-")
End Function |
Partager