Re : Tronquer avec conditions
Le Forum,
JP,
Merci de ta réponse mais j'avais déjà trouvé une solution.
Et pour conclure, j'espère, ce fil, j'aimerais vous faire partager le résultat.
Merci à pierrejean
Option Explicit
Sub test()
Dim tot As String
Dim colonne As Integer
Dim cell As Range
Dim n As Integer
Dim x, y, z As Integer
Dim unecase As String
Dim LF1, LF2 As Long
LF1 = 2
LF2 = 2
For Each cell In Sheets("source").Range("f2:f" & Sheets("source").Range("f65536").End(xlUp).Row)
tot = Sheets("source").Cells(LF1, 6)
y = Len(tot)
While Len(tot) > 63
unecase = Left(tot, 64)
For n = Len(unecase) To 1 Step -1
If Mid(unecase, n, 1) = " " Then
x = n
Exit For
End If
Next n
If Left(tot, 1) <> " " Then
unecase = Left(tot, x)
Sheets("cible").Cells(LF2, 6) = unecase & String((64 - x), " ")
If Len(Sheets("cible").Cells(LF2, 6)) > 0 Then
For z = 5 To 1 Step -1
Sheets("cible").Cells(LF2, 6).Offset(0, (z - 6)) = Sheets("source").Cells(LF1, z)
Next
End If
End If
tot = Mid(tot, x + 1, Len(tot) - x) & String((64 - x), " ")
y = Len(tot)
If Left(tot, 1) <> " " Then
For z = 1 To 5
Sheets("cible").Cells(LF2, z) = Sheets("source").Cells(LF1, z)
Next
LF2 = LF2 + 1
End If
Wend
If Left(tot, 1) <> " " Then
unecase = Left(tot, x)
Sheets("cible").Cells(LF2, 6) = unecase & String((64 - x), " ")
If Len(Sheets("cible").Cells(LF2, 6)) > 0 Then
For z = 5 To 1 Step -1
Sheets("cible").Cells(LF2, 6).Offset(0, (z - 6)) = Sheets("source").Cells(LF1, z)
Next
End If
End If
If Left(tot, 1) <> " " Then
Sheets("cible").Cells(LF2, 6) = unecase & String((64 - x), " ")
y = Len(tot)
For z = 1 To 5
Sheets("cible").Cells(LF2, z) = Sheets("source").Cells(LF1, z)
Next
End If
LF2 = LF2 + 1
Sheets("cible").Cells(LF2, 6) = tot
LF1 = LF1 + 1
Next
End Sub
Sub effacer()
Sheets("cible").Range("a2:f" & Sheets("cible").Range("f65536").End(xlUp).Row).ClearContents
End Sub