Filtre automatique entre deux dates
Bonjour,
Je sais que le sujet a déjà été traiter 52 miles fois, mais je n'arrive pas à comprendre pourquoi cela ne fonctionne pas.
J'ai fais une macro qui trie entre deux dates mais celle-ci ne fonctionne pas.
Code:
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
| Sub Macro2Date()
Dim Datedebut As String
Dim Datefin As String
Dim A As Date
Dim B As Date
Datedebut = InputBox("Entrer la date de debut au format JJ/MM/AAAA", _
"Format jour/mois/année")
If Datedebut = "" Then Exit Sub
Datefin = InputBox("Entrer la date de fin au format JJ/MM/AAAA", _
"Format jour/mois/année")
If Datefin = "" Then Exit Sub
If Datefin > Datedebut Then
A = Datefin
B = Datedebut
Else
: A = Datedebut
B = Datefin
End If
If Datedebut = "" Then Exit Sub
If Datefin = "" Then Exit Sub
If IsDate(A) And IsDate(B) Then
With Sheets("Base de données")
.Range("$A$1:$BY$8").AutoFilter Field:=31, _
Criteria1:=">=" & Format(A, "mm/dd/yyyy"), Operator:=xlAnd, _
Criteria2:="<=" & Format(B, "mm/dd/yyyy")
End With
End If
End Sub |
Avez vous des indication à me donnez.
Cordialement,
Passepartout007
Re: qu'elle type de variable cela entraine ?
Bonjour dans la déclaration des différentes variable que me propose tu de mettre actuellement j'ai :
Code:
1 2 3 4
| Dim Datedebut As String
Dim Datefin As String
Dim A As Date
Dim B As Date |
Cela me provoque une incompatibilité de Type à l'application de :
Code:
A = CDbl(Datedebut)
J'ai bien essayer
Code:
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
| Sub Macro2Date()
Dim Datedebut As String
Dim Datefin As String
Dim A As Date
Dim B As Date
Datedebut = InputBox("Entrer la date de debut au format JJ/MM/AAAA", _
"Format jour/mois/année")
If Datedebut = "" Then Exit Sub
Datefin = InputBox("Entrer la date de fin au format JJ/MM/AAAA", _
"Format jour/mois/année")
If Datefin = "" Then Exit Sub
If Datefin > Datedebut Then
A = Datefin
B = Datedebut
Else
: A = Datedebut
B = Datefin
End If
A = CDbl(A)
B = CDbl(B)
MsgBox A
If Datedebut = "" Then Exit Sub
If Datefin = "" Then Exit Sub
If IsDate(A) And IsDate(B) Then
With Sheets("Base de données")
.Range("$A$1:$BY$8").AutoFilter Field:=31, _
Criteria1:=">=" & A, Operator:=xlAnd, _
Criteria2:="<=" & B
End With
End If
End Sub |
Mais cela ne fonctionne pas non plus.
Cordialement,
Passepartout007