Option Explicit
Sub test()
Dim FD As Worksheet
Set FD = Worksheets(ActiveSheet.Name)
' Suppression des valeurs consolidation
FD.Range("E3:E" & FD.Range("D1048576").End(xlUp).Row).ClearContents
Dim TbBis(1 To 3) As Variant
TbBis(1) = FD.Range("A4:B" & FD.Range("A1048576").End(xlUp).Row).Value
Set TbBis(2) = FD.Range("A4:B" & FD.Range("A1048576").End(xlUp).Row)
TbBis(3) = FD.Range("D3:E" & FD.Range("D1048576").End(xlUp).Row).Value
Dim i As Integer, j As Integer
' Suppression de la surbrillance
TbBis(2).Interior.Pattern = xlNone
' Indentification Doublon (Mois et Code établissement)
For i = LBound(TbBis(1), 1) To UBound(TbBis(1), 1)
For j = i + 1 To UBound(TbBis(1), 1)
If TbBis(1)(i, 2) <> Empty And TbBis(1)(j, 2) <> Empty And Month(TbBis(1)(i, 1)) & TbBis(1)(i, 2) = Month(TbBis(1)(j, 1)) & TbBis(1)(j, 2) Then
TbBis(1)(j, 2) = "d " & TbBis(1)(j, 2)
End If
Next j
Next i
For i = LBound(TbBis(1), 1) To UBound(TbBis(1), 1)
If TbBis(1)(i, 2) Like "*" & "d" & "*" Then
TbBis(2)(i, 2).Interior.Color = 65535
End If
Next i
' Consolidation (Nb Code établissement par mois sans doublon)
For i = LBound(TbBis(3), 1) To UBound(TbBis(3), 1)
For j = LBound(TbBis(1), 1) To UBound(TbBis(1), 1)
If TbBis(1)(j, 2) <> Empty And LCase(TbBis(3)(i, 1)) = Format(TbBis(1)(j, 1), "mmmm") And Not TbBis(1)(j, 2) Like "*" & "d" & "*" Then
TbBis(3)(i, 2) = TbBis(3)(i, 2) + 1
End If
Next j
Next i
' RESTITUTION DU TABLEAU CONSOLIDATION AVEC LES VALEURS DANS LA FEUILLE
FD.[E3].Resize(UBound(TbBis(3), 1)) = Application.Index(TbBis(3), , 2)
' Libére la mémoire
Erase TbBis
Set FD = Nothing
i = Empty: j = Empty
End Sub