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 38 39 40 41 42 43 44
| Sub Compile()
Dim LastLig As Long, i As Long
Dim Tb
Application.ScreenUpdating = False
With Worksheets("Feuil1") 'Adapte le nom de ta feuille
LastLig = .Cells(.Rows.Count, "A").End(xlUp).Row
If LastLig > 2 Then
Tb = .Range("A1:E" & LastLig + 1).Value
For i = UBound(Tb, 1) To 3 Step -1
If Not NonDoublons(Tb, i) Then
Tb(i - 1, UBound(Tb, 2)) = Tb(i - 1, UBound(Tb, 2)) & " " & Tb(i, UBound(Tb, 2))
Efface Tb, i
End If
Next i
.Range("A1:E" & LastLig + 1).Value = Tb
End If
End With
End Sub
'------------------------------------------
Private Function NonDoublons(ByVal Tb, ByVal i As Long) As Boolean
Dim k As Byte
For k = 1 To UBound(Tb, 2) - 1
If Tb(i - 1, k) <> Tb(i, k) Then
NonDoublons = True
Exit For
End If
Next k
End Function
'------------------------------------------
Private Sub Efface(ByRef Tb, ByVal i As Long)
Dim j As Long
Dim k As Byte
For j = i To UBound(Tb, 1) - 1
For k = 1 To UBound(Tb, 2)
Tb(j, k) = Tb(j + 1, k)
Tb(j + 1, k) = Empty
Next k
Next j
End Sub |
Partager