Private Sub Worksheet_Activate()
Dim d As Object, c As Range, f, tablo, ncol%, lig&, col%, moisprec As Byte, j As Variant, dat&, w As Worksheet, i&, k As Variant
Application.ScreenUpdating = False
On Error Resume Next
'---liste des noms---
Set d = CreateObject("Scripting.Dictionary")
For Each c In Sheets("Noms").[C1].CurrentRegion.Resize(, 1)
d(c.Value) = ""
Next
With Sheets("Résultat")
.Rows("7:" & .Rows.Count).ClearContents 'RAZ
.Rows("7:" & .Rows.Count).FormatConditions.Delete 'RAZ MFC
.[A7].Resize(d.Count) = Application.Transpose(d.keys)
With .[A6].CurrentRegion
f = .Rows(1).Formula 'mémorisation des formules
tablo = .Value2 'matrice, plus rapide
ncol = UBound(tablo, 2)
'---remplissage du tableau
For lig = 2 To d.Count + 1
For col = 2 To ncol Step 4
moisprec = 0: j = "x"
1 dat = DateSerial(Year(tablo(1, col)), Month(tablo(1, col)) - moisprec, 1)
Set w = Nothing
Set w = Sheets(Format(dat, "mmm"))
If Not w Is Nothing Then
For i = 9 To 101 Step 23
j = Application.Match(tablo(1, col), w.Rows(i), 0)
If IsNumeric(j) Then
k = Application.Match(tablo(lig, 1), w.Cells(i + 1, 1).Resize(22), 0)
If IsNumeric(k) Then
tablo(lig, col) = w.Cells(i + k, j)
tablo(lig, col + 1) = w.Cells(i + k, j + 1)
tablo(lig, col + 2) = w.Cells(i + k, j + 2)
tablo(lig, col + 3) = w.Cells(i + k, j + 3)
End If
Exit For
End If
Next i
End If
If moisprec = 0 And Not IsNumeric(j) Then moisprec = 1: GoTo 1
Next col, lig
'---restitution des valeurs et des formules---
.Value = tablo
.Rows(1) = f
'---MFC---
With .Rows(2).Resize(d.Count)
.FormatConditions.Add xlTextString, String:="Repos", TextOperator:=xlContains
.FormatConditions(1).Interior.ColorIndex = 6 'jaune
End With
End With
Application.Goto .[A1], True 'cadrage
End With
End Sub