Sub Meteo()
duree = Timer
Dim wbf As Worksheet
Set dest = ThisWorkbook.Worksheets("Feuil1")
dest.Cells.Clear
chemin = "C:\Users\client\Downloads\Station_Agadir\"
fich = Dir(chemin & "*-GCM-*.txt", vbNormal)
While fich <> ""
fichier = chemin & fich
Workbooks.OpenText Filename:= _
fichier, Origin:= _
xlMSDOS, StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote _
, ConsecutiveDelimiter:=True, Tab:=True, Semicolon:=False, Comma:=False _
, Space:=True, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), Array _
(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), Array(9, 1), Array( _
10, 1), Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 1), Array(15, 1), Array(16, 1), _
Array(17, 1), Array(18, 1), Array(19, 1), Array(20, 1), Array(21, 1)), _
TrailingMinusNumbers:=True
Set wbf = ActiveWorkbook.Worksheets(1)
debut = 14245: fin = 23741
Set r = wbf.Cells(debut, 2).Resize(fin - debut + 1, 21)
t = r.Value
wbf.Parent.Close False
dest.Parent.Activate
dern = dest.Cells(dest.Rows.Count, 5).End(xlUp).Row + 1
If dern < 2 Then dern = 2
dest.Cells(dern, 5).Select
dest.Cells(dern, 5).Resize(UBound(t, 1), UBound(t, 2)).Value = t
dest.Cells(dern, 1).Select
' placer les moyennes dans l'onglet "Base" en colonne D
' insérer les dates dans la colonne A
' le nom de la station dans la colonne B
' Tmax ou Tmin dans la colonne C
dest.Cells(dern, 1).Value = "2000-01-01"
dest.Cells(dern, 1).AutoFill Destination:=dest.Cells(dern, 5).Resize(UBound(t, 1), UBound(t, 2)).Columns(-3), Type:=xlFillDefault
strRng = "E" & dern & ":X" & dern
formule = "=AVERAGE(" & strRng & ")" '"=AVERAGE(E2:X2)"
dest.Cells(dern, "D").Formula = formule
dest.Cells(dern, "D").AutoFill Destination:=dest.Cells(dern, 5).Resize(UBound(t, 1), UBound(t, 2)).Columns(-0), Type:=xlFillDefault
nn = InStrRev(fich, ".")
dest.Cells(dern, "E").Resize(UBound(t, 1), UBound(t, 2)).Columns(-2).Value = Split(fich, "-")(2) & Mid(fich, nn - 3, 3)
dest.Cells(dern, "E").Resize(UBound(t, 1), UBound(t, 2)).Columns(-1).Value = Split(fich, "-")(0)
fich = Dir
Wend
dest.Cells(1, "D").Value = "Moyenne"
dest.Cells(1, "D").Select
duree = Timer - duree
Debug.Print duree & " sec"
End Sub