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 45 46 47 48 49 50 51
| Private Sub CommandButton1_Click()
Dim dateref As Date 'date a laquelle on se situe virutellement - Aujourd'hui par défaut
Dim datecontrat As Date 'date de signature du contrat (qui doit antécédente à date de référence)
Dim yrlookup As Integer 'Année que l'on souhaite analyser dans la suite du protocole(généralement égale ou supérieur d'une à deux années par rapport à la date de référence)
Dim mtlookup As Integer 'Mois que l'on souhaite analyser (à rendre facultatif)
Dim DernLig1 As Long
Dim DernCol1 As Integer
Dim DernLig2 As Long
Dim DernCol2 As Integer
If Not IsEmpty(Worksheets("test").Range("A2")) Then
Worksheets("test").Cells(2, 1).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.ClearContents
End If
DernCol1 = Worksheets("RES").Range("A1").End(xlToRight).Column
DernLig1 = 1 'première ligne à vérifier
Do While Not IsEmpty(Worksheets("RES").Range("A" & DernLig1))
DernLig1 = DernLig1 + 1
Loop
dateref = TextBox1.Value
yrlookup = TextBox2.Value
i = 2
J = 2
Do Until i = DernLig1
datecontrat = Format(DateSerial(Year(Cells(i, 3)), Month(Cells(i, 3)), Day(Cells(i, 3))), "dd/mm/yyyy")
datereception = Format(DateSerial(Year(Cells(i, 2)), Month(Cells(i, 2)), Day(Cells(i, 2))), "dd/mm/yyyy")
If (datecontrat < dateref) And (Year(datereception) = yrlookup) And (Worksheets("RES").Range("D" & i) = "Faux") Then
Worksheets("RES").Range(Cells(i, 1), Cells(i, DernCol1)).Select
Selection.Copy
Worksheets("test").Select
Range("A" & J).Select
ActiveSheet.Paste
Worksheets("RES").Select
i = i + 1
J = J + 1 '(pour que la ligne où sont collé les infos voulus soit augmenté de 1 à chaque fois que la condition est vérifié)
Else
i = i + 1
End If
Loop
Worksheets("test").Select
Unload Me
End Sub |
Partager