Private Sub Worksheet_Activate()
Dim deb As Range, critere As Range, a(), w As Worksheet, n%, i As Variant
Set deb = [D12] 'adapter éventuellement
Set critere = [E9] 'adapter éventuellement
'---MAJ de la liste des mois---
ReDim a(1 To Worksheets.Count, 1 To 2)
For Each w In Worksheets
If IsDate(w.Name) Then
n = n + 1
a(n, 1) = CDate(w.Name)
a(n, 2) = w.Name
End If
Next
Application.ScreenUpdating = False
critere.Validation.Delete 'RAZ
With Sheets("DATA")
.Range("A2:B" & .Rows.Count) = Empty
.[A2].Resize(n, 2) = a
.[A2].Resize(n, 2).Sort .[A2], Header:=xlNo 'tri sur les dates
.[B2].Resize(IIf(n, n, 1)).Name = "Sheetlist" 'plage nommée
i = Application.Match(critere, [Sheetlist], 0)
End With
If n Then critere.Validation.Add xlValidateList, Formula1:="=Sheetlist"
'---remplissage de la feuille RECAP---
Rows(deb.Row & ":" & Rows.Count).RowHeight = 22 'hauteur modifiable
Rows(deb.Row & ":" & Rows.Count) = Empty 'RAZ
If n = 0 Or IsError(i) Then Exit Sub
With Sheets(CStr(critere)).[A9].CurrentRegion.Offset(2)
n = .Rows.Count - 2
If n < 1 Then Exit Sub
deb.Resize(n) = .Columns(1).Value
deb(1, 2).Resize(n, [Codes].Count) = .Cells(1, 34).Resize(n, [Codes].Count).Value
deb(n + 1) = "TOTAL"
deb(n + 1, 2).Resize(, [Codes].Count) = "=SUM(R[-" & n & "]C:R[-1]C)"
End With
With Me.UsedRange: End With 'actualise la barre de défilement verticale
ActiveWindow.ScrollRow = 1
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, [E9]) Is Nothing Then Worksheet_Activate
End Sub