Bonjour,
j'ai bien peur mayekeul qu'il y ait encore des loupés avec ton dernier code …
Sinon voici une approche plus simple :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| Sub Demo()
Application.ScreenUpdating = False
With [A1].CurrentRegion
For R& = 1 To .Rows.Count
N& = Application.CountA(.Rows(R).Columns("B:D"))
If N = 1 And .Cells(R, 2).Value = "" Then
.Cells(R, 3 - (.Cells(R, 3).Value = "")).Cut .Cells(R, 2)
ElseIf N = 2 And .Cells(R, 4).Value > "" Then
C& = 3 + (.Cells(R, 2).Value = "")
.Cells(R, C + 1).Resize(, 4 - C).Cut .Cells(R, C)
End If
Next
End With
Application.ScreenUpdating = True
End Sub |
S'il y a une ligne de titre, commencer alors à 2 la boucle de la ligne n°5 …
Voici un code plus véloce à l'aide d'une variable tableau :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| Sub SpeedDemo()
TS = [A1].CurrentRegion.Columns("B:D").Value
N& = UBound(TS)
For R& = 1 To N
For C& = 2 To 1 Step -1
If TS(R, C) = "" And TS(R, C + 1) > "" Then
TS(R, C) = TS(R, C + 1): TS(R, C + 1) = ""
If C = 1 And TS(R, 3) > "" Then TS(R, 2) = TS(R, 3): TS(R, 3) = ""
End If
Next C
Next R
[B1:D1].Resize(N).Value = TS
Erase TS
End Sub |
__________________________________________________________________________________________
Merci de cliquer sur

pour chaque message ayant aidé puis sur

pour clore cette discussion …
Partager