Option Explicit
Public debut As Date, fin As Date
Sub mise_a_jour()
Dim tmp1$, tmp2 As Date, msg1$, msg2$
With ActiveSheet 'feuille de travail
'param /defaut
debut = .Range("BE1").Value
fin = .Range("BE2").Value
'questions
On Error GoTo E
tmp1 = InputBox("Confimez la date de départ à supprimer", "Actualisation", debut)
If tmp1 = "" Then Exit Sub
msg1 = "date de départ au format jj/mm/aaaa": msg2 = "Actualisation": tmp2 = debut
debut = CDate(tmp1)
tmp1 = InputBox("Confimez la date de fin à supprimer", "Actualisation", fin)
If tmp1 = "" Then Exit Sub
msg1 = "date de fin au format jj/mm/aaaa": msg2 = "Actualisation": tmp2 = fin
fin = CDate(tmp1)
On Error GoTo 0
.Range("BF1").Value = debut
.Range("BF2").Value = fin
toto .Name 'nom de la feuille de travail
End With
Exit Sub
'
E: 'gestion d'erreurs
tmp1 = InputBox(msg1, msg2, tmp2)
If tmp1 = "" Then Exit Sub
Resume
End Sub
Sub toto(sh$)
Dim i&, j&, k&, h&, g&, d&, clef&, oDat, sDat()
Dim DMin As Date, DMax As Date
'===== description de la plage de données =====
h = 1 'n° de la première (ligne de titre)
g = 1 'rang de la première colonne
d = 5 'rang de la dernière colonne
clef = 1 'rang de la colonne de référence
'==============================================
oDat = tata(sh, h, g, d, clef) 'extraction des données
If Not IsEmpty(oDat) Then
DMin = debut 'date de début
DMax = fin 'date de fin
k = 1
ReDim sDat(1 To UBound(oDat, 1), 1 To 1 + d - g)
For j = 1 To 1 + d - g: sDat(k, j) = oDat(k, j): Next
For i = 2 To UBound(oDat, 1)
If DMin > oDat(i, clef) Or oDat(i, clef) > DMax Then
k = k + 1
For j = 1 To 1 + d - g: sDat(k, j) = oDat(i, j): Next
End If
Next i
Sheets(sh).Cells(h, g).Resize(UBound(oDat, 1), 1 + d - g).Value = sDat 'restitution des données sélectionnées
End If
End Sub
Function tata(sh$, h&, g&, d&, clef&)
Dim i&, oDat
With Sheets(sh)
i = .Cells(.Rows.Count, clef).End(xlUp).Row
If i > h Then
oDat = .Range(.Cells(h, d), .Cells(i, g)).Value
End If
End With
tata = oDat
End Function