1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| Sub Isoler_Les_Elements()
Dim L As Long, a As Long, c As Long, DerLig As Long
Dim e As Object
Application.ScreenUpdating = False
DerLig = Range("A" & Rows.Count).End(xlUp).Row
For L = 2 To DerLig
a = 1
c = 2
NbCarTexte = Len(Cells(L, a))
ReDim Nb(NbCarTexte) As Long
For i = 1 To 4
Set e = Cells(L, a).Find(" ")
If Not e Is Nothing Then
NbCar = InStr(1, Cells(L, a), " ", 1)
Do
NbCar = NbCar + 1
Loop While Mid(Cells(L, a), NbCar, 1) = " "
End If
Cells(L, c) = Right(Cells(L, a), Len(Cells(L, a)) - NbCar + 1)
Nb(i) = NbCar
c = c + 1
a = a + 1
Next i
'les espaces sont ajoutés à la suite de chaque élément
For i = 1 To 4
Cells(L, i) = Application.WorksheetFunction.Replace(Cells(L, i), Nb(i), Len(Cells(L, i + 1)), "")
Next i
'les espaces sont ajoutés avant chaque élément, ceux derrière les éléments sont supprimés
For i = 4 To 1 Step -1
Esp = Split(Cells(L, i), " ", , 1)
Cells(L, i).Replace What:=" ", Replacement:="", LookAt:=xlPart
Cells(L, i + 1) = Application.Rept(" ", UBound(Esp)) & Cells(L, i + 1)
Next i
Next L
End Sub |
Partager