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
| Sub Macro3()
Dim i As Long, DerLigne As Long
Dim date1 As Date, date2 As Date
' On vide la liste
UserForm1.ListBox1.Clear
'On trouve la ligne à partir de laquelle il n y a plus d'informations
Dernligne = Sheets("Liste des usagers").Range("B" & Rows.Count).End(xlUp).Row
Sheets("Liste des usagers").Rows("3:DernLigne").Select
Selection.Sort Key1:=Range("B3"), Order1:=xlAscending, Key2:=Range("C3") _
, Order2:=xlAscending, Header:=xlYes, OrderCustom:=1, MatchCase:=False _
, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:= _
xlSortNormal
For i = 3 To Dernligne
date1 = DateSerial(Year(Now), Month(Now), Day(Now)) 'On stocke l année, le mois, et le jour dans cette variable
date2 = Sheets("Liste des usagers").Cells(i, 4).Value 'On stocke la date d expiration
If date2 - date1 < 30 Then
UserForm1.ListBox1.AddItem (Cells(i, 2) & " " & Cells(i, 3) & " Carte n° " & Cells(i, 1) & " ---> " & date2 - date1 & " " & "jour(s)")
Rows(i & ":" & i).Select
Selection.Font.ColorIndex = 3
Else
Rows(i & ":" & i).Select
Selection.Font.ColorIndex = 1
End If |
Partager