Sub Traitement()
Dim derlig&, i&, j&, plage As Range, col As Byte, txt$, lig&, sup As Range
Application.ScreenUpdating = False
Application.DisplayAlerts = False 'si on relance la macro
On Error Resume Next
'ouvre le fichier texte
Workbooks.Open ThisWorkbook.Path & "\une partie.txt" 'ou un autre chemin d'accès
If Err Then MsgBox "Fichier introuvable !": Exit Sub
'copie la feuille (sécurité)
Sheets(1).Copy After:=Sheets(1)
'renomme les feuilles
Sheets(2).Name = Sheets(1).Name & " (traité)"
Sheets(1).Name = Sheets(1).Name & " (original)"
derlig = Range("A65536").End(xlUp).Row
For i = 1 To derlig
If Left(Cells(i, 1), 2) = "I " Then
For j = i + 1 To derlig
If Left(Cells(j, 1), 2) = "I " Or Cells(j, 1) = Chr(12) Then Exit For
Next
Set plage = Cells(i, 1).Resize(j - i)
'convertit la plage vers les cellules (largeur fixe)
plage.TextToColumns Destination:=Cells(i, 1), DataType:=xlFixedWidth
'supprime la colonne des "M."
If Cells(i, 3) = "M." Then Cells(i, 3).Resize(j - i).Delete xlToLeft
'concatène verticalement
For col = 2 To Cells(i, 256).End(xlToLeft).Column
txt = Cells(i, col)
For lig = i + 1 To j - 1
txt = txt & IIf(Left(Cells(lig, col), 2) Like "? *", "", " ") & Cells(lig, col)
Next
Cells(i, col) = Application.Trim(txt) 'supprime les espaces inutiles
Next
'concatène horizontalement pour ramener la date en colonne N
While Cells(i, "O") <> ""
Cells(i, "H") = Cells(i, "H") & " " & Cells(i, "I")
Cells(i, "I").Resize(j - i).Delete xlToLeft 'supprime la colonne concaténée
Wend
'transforme le texte en date
Cells(i, "N") = CDate(Cells(i, "N"))
'supprime la colonne des "I" (facultatif)
'plage.Delete xlToLeft
'crée l'union des lignes à supprimer
If j > i + 1 Then
Set plage = Cells(i + 1, 1).Resize(j - i - 1)
Set sup = Union(IIf(sup Is Nothing, plage, sup), plage)
End If
i = j - 1
End If
Next
If Not sup Is Nothing Then sup.EntireRow.Delete 'supprime les lignes superflues
Cells.Replace "M.", "", LookAt:=xlPart
Cells.Replace "- ", "-"
Cells.Replace "MANOMET RE", "MANOMETRE" 'vraiment, vraiment!!
'largeurs des colonnes
'Columns(1).ColumnWidth = 18 'ou autre valeur (si les "I" sont supprimés)
Columns("B:N").AutoFit 'ajustement automatique
End Sub