Option Explicit
Sub CorrigeErrRefEtendu()
Application.ScreenUpdating = False
Dim t As Single
't = Timer
' Feuil 1 Résultat : Colonne N et O
Dim FRes As Worksheet
Set FRes = Worksheets("feuil1")
Dim ResPlage As Range
Set ResPlage = FRes.Range(FRes.Cells(2, 1), FRes.Cells(FRes.Cells(1048576, 1).End(xlUp).Row, FRes.Cells(1, 16384).End(xlToLeft).Column))
Dim Tres()
ReDim Tres(1 To ResPlage.Rows.Count, 1 To 2) ' Ecriture Via VAriable tableau Plus Rapide que Par Variable Objet Range
Dim Dic1 As Object
Set Dic1 = CreateObject("scripting.dictionary") ' Colonne N
Dim Dic2 As Object
Set Dic2 = CreateObject("scripting.dictionary") ' Colonne 0
Dim Val As Range
For Each Val In ResPlage.Resize(ResPlage.Rows.Count, 1)
Dic1.Add Val.Text & "-" & Val.Offset(, 3).Text & "-" & Val.Offset(, 6).Text, 0
Dic2.Add Val.Text & "-" & Val.Offset(, 3).Text & "-" & Val.Offset(, 6).Text & "-" & FRes.Cells(1, 15), 0
Next
'
' -----------------------------------------------------------------------------------------------------------------------------------------------
' Feuil base : Sheet 1
Dim FBase As Worksheet
Set FBase = Worksheets("Sheet 1")
Dim Tbase() As Variant
Tbase = FBase.Range(FBase.Cells(2, 1), FBase.Cells(FBase.Cells(1048576, 1).End(xlUp).Row, FBase.Cells(1, 16384).End(xlToLeft).Column))
'
' -----------------------------------------------------------------------------------------------------------------------------------------------
' Resultat ' Colonne N
Dim Cle As Variant
Dim i As Long
For Each Cle In Dic1.keys
If Dic1.Exists(Cle) Then
For i = LBound(Tbase, 1) To UBound(Tbase, 1)
If Tbase(i, 2) & "-" & Tbase(i, 5) & "-" & Tbase(i, 8) = Cle Then
Dic1.Item(Cle) = Dic1.Item(Cle) + 1
End If
Next i
End If
Next
For Each Val In ResPlage.Resize(ResPlage.Rows.Count, 1)
'Val.Offset(, 13) = Dic1.Item(Val.Text & "-" & Val.Offset(, 3).Text & "-" & Val.Offset(, 6).Text) ' ..... Ecriture Range Long
Tres(Val.Row - 1, 1) = Dic1.Item(Val.Text & "-" & Val.Offset(, 3).Text & "-" & Val.Offset(, 6).Text) ' .. Ecriture Variable Tableau Rapide
Next
i = Empty
' ---------------------------------------------------------
' Resultat ' Colonne O
For Each Cle In Dic2.keys
If Dic2.Exists(Cle) Then
For i = LBound(Tbase, 1) To UBound(Tbase, 1)
If Tbase(i, 2) & "-" & Tbase(i, 5) & "-" & Tbase(i, 8) & "-" & Tbase(i, 11) = Cle Then
Dic2.Item(Cle) = Dic2.Item(Cle) + 1
End If
Next i
End If
Next
For Each Val In ResPlage.Resize(ResPlage.Rows.Count, 1)
'Val.Offset(, 14) = Dic2.Item(Val.Text & "-" & Val.Offset(, 3).Text & "-" & Val.Offset(, 6).Text & "-" & FRes.Cells(1, 15)) ' ..... Ecriture Range Long
Tres(Val.Row - 1, 2) = Dic2.Item(Val.Text & "-" & Val.Offset(, 3).Text & "-" & Val.Offset(, 6).Text & "-" & FRes.Cells(1, 15)) ' .. Ecriture Variable Tableau Rapide
Next
' resultat via Variable tableau Rapide
FRes.Cells(2, 14).Resize(UBound(Tres, 1), UBound(Tres, 2)) = Tres
'MsgBox Timer - t
Application.ScreenUpdating = True
End Sub