Sub Importer()
Dim t#, liste, x%, texte$, a$(), n&, i&, texte1$, texte2$, s, ub%, j%
t = Timer
liste = Array("FULL", "SUSPENDED", "FROZEN", "IMPORTED") 'liste pour la colonne STATUS, à adapter
x = FreeFile
Open ThisWorkbook.Path & "\medialist.txt" For Input As #x
While Not EOF(x) 'fin du fichier
Line Input #x, texte
texte = Application.Trim(texte) 'SUPPRESPACE
If Replace(texte, "-", "") <> "" Then
If texte Like "Server*" Then
texte = Replace(texte, " ", Chr(160))
ReDim Preserve a(n)
a(n) = texte
n = n + 1
i = 0
Else
Select Case i Mod 3
Case 0: texte1 = texte
Case 1: texte2 = texte
Case 2
If texte Like "On*" Then texte = Replace(texte, " ", Chr(160))
texte = texte1 & " " & texte2 & " " & texte
s = Split(texte)
ub = UBound(s)
If s(ub - 2) = liste(0) And s(ub - 1) = liste(1) Then
s(ub - 2) = liste(0) & Chr(160) & liste(1)
s(ub - 1) = ""
ElseIf Not s(ub) Like "On*" Then
If IsError(Application.Match(s(ub - 1), liste, 0)) Then s(ub) = Chr(160) & " " & s(ub)
End If
For j = 0 To ub
If s(j) = "STATUS" Then s(j) = s(j - 1) & Chr(160) & s(j) & Chr(160) & s(j + 1): s(j - 1) = "": s(j + 1) = ""
If IsDate(s(j)) Or s(j) = "last" Then s(j) = s(j) & Chr(160) & s(j + 1): s(j + 1) = ""
Next j
ReDim Preserve a(n)
a(n) = Application.Trim(Join(s))
n = n + 1
End Select
i = i + 1
End If
End If
Wend
Close #x
'---transposition et conversion---
ReDim b(n - 1, 12) 'base 0
For i = 0 To UBound(b)
s = Split(a(i))
For j = 0 To UBound(s)
b(i, j) = Replace(s(j), Chr(160), " ")
If IsDate(b(i, j)) Then b(i, j) = CDate(b(i, j))
Next j, i
'---restitution---
Application.ScreenUpdating = False
Cells.Delete 'RAZ
[A1].Resize(n, 13) = b
[D:E,J:L].Columns.AutoFit 'ajuste les largeurs
With ActiveSheet.UsedRange: End With 'actualise les barres de défilement
Application.ScreenUpdating = True
MsgBox "Importation de " & n & " lignes réalisée en " & Format(Timer - t, "0.00 \sec"), , "Import"
End Sub