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
| Sub Test()
Dim tb, DL As Long, i As Long
With Sheets("Feuil1")
DL = derlig_reelle(.Columns(1))
tb = .Range("A2:D" & DL).Value
'1ère valeur enregistrée comme début
tb(1, 3) = tb(1, 1)
For i = LBound(tb, 1) To UBound(tb, 1) - 1
If tb(i, 2) <> tb(i + 1, 2) Then
tb(i, 4) = tb(i, 1)
tb(i + 1, 3) = tb(i + 1, 1)
End If
Next
'dernière valeur
If tb(i, 2) = tb(i - 1, 2) Then
tb(i, 3) = ""
tb(i, 4) = tb(i - 1, 4)
tb(i - 1, 4) = ""
End If
.Range("A2").Resize(UBound(tb, 1), 4) = tb
End With
End Sub
Private Function derlig_reelle(plage As Range) As Long
If WorksheetFunction.CountA(plage) = 0 Then derlig_reelle = plage.Cells(1, 1).Row: Exit Function
derlig_reelle = plage.Find("*", , , , , xlPrevious).Row
End Function |
Partager