1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| Option Explicit
Public Const rowDuration = 2 ' Target: maximal difference of dates
Public Const colDuration = 1
Public Const nbrDate = 4
Public Const rowDateStart = rowDuration + 1 ' Source: first date to be sorted
Public Const rowDateEnd = rowDateStart + nbrDate - 1 ' Last date to be sorted
Public Const colDate = 1
Sub SortDate()
Dim rngDate As Range, dateMax As Date, dateMin As Date, strNbrDay As String, nbrDay As Integer
Set rngDate = Range(Cells(rowDateStart, colDate), Cells(rowDateEnd, colDate))
rngDate.Sort Key1:=Cells(rowDateStart, colDate), Order1:=xlDescending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
dateMax = Cells(rowDateStart, colDate)
dateMin = Cells(rowDateEnd, colDate)
nbrDay = DateDiff("d", dateMin, dateMax)
strNbrDay = IIf(nbrDay > 0, CStr(nbrDay) + " jours ", "")
Cells(rowDuration, colDuration) = strNbrDay + Format(dateMax - dateMin, "HH:MM:SS")
End Sub |
Partager