Private Sub Workbook_Activate()
Dim chemin$, fichier$, col%, coldat%, lig&, i&, ouv As Boolean, w As Worksheet, h&
chemin = Me.Path & "\" 'à adapter si nécessaire
fichier = "fichier source.xls" 'à adapter
col = 4 'nombre de colonnes paramétré
coldat = 3 'colonne des dates
lig = 3 '1ère ligne de données
i = lig
Application.ScreenUpdating = False
On Error Resume Next
'---si le fichier source est fermé on l'ouvre---
If IsError(Workbooks(fichier)) Then
Workbooks.Open chemin & fichier
ouv = True
End If
On Error GoTo 0
With Feuil1 'CodeName de la feuille de restitution
.Cells(i, 1).Resize(.Rows.Count - i + 1, col).ClearContents 'RAZ
'---récupération des données---
For Each w In Workbooks(fichier).Worksheets
h = w.Range("A" & w.Rows.Count).End(xlUp).Row - lig + 1
If h > 0 Then
.Cells(i, 1).Resize(h, col) = w.[A3].Resize(h, col).Value
i = i + h
End If
Next
'---colonne auxiliaire col + 1---
For i = lig To i - 1
.Cells(i, col + 1) = DateSerial(2004, Month(.Cells(i, coldat)), Day(.Cells(i, coldat)))
Next
.Cells(lig, 1).Resize(i - lig, col + 1).Sort .Columns(col + 1), _
xlAscending, .Columns(coldat), Header:=xlNo
.Columns(col + 1).ClearContents
End With
'---fermeture du fichier s'il a été ouvert---
If ouv Then
Application.EnableEvents = False
Workbooks(fichier).Close False
Application.EnableEvents = True
End If
End Sub