Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

filtre sur date valeur nul???? et filtre fonctionne pas!

1 réponse
Avatar
christophe
bonjour a tous,

petite question pour vous les spécialistes!!!!

j'ai un filtre sur date en vba mais quand je lance la macro il me transforme
les valeur de dates en chiffres et donc il ne trouve rien!

voici le code:

Dim cir(6) As String, Bt As String, Rg As Range
Dim exloc()
Dim date1 As Date
Dim date2 As Date
Dim date3 As Date
Dim date4 As Date

loc1 = UCase(Loc)
exloc = Array("CI", "EX", "ES", "LT", "PA", "RE", "SA", "SR", "ST",
"TO", "VR")
If bat.Value = "Goldbell II" Then
Bt = "GOL"
ElseIf bat.Value = "KAD" Then
Bt = "KAD"
ElseIf bat.Value = "Tour A" Then
Bt = "TOA"
ElseIf bat.Value = "Tour B" Then
Bt = "TOB"
ElseIf bat.Value = "Schuman" Then
Bt = "SCH"
ElseIf bat.Value =
"Senningerberg" Then
Bt = "SEN"
End If
Sheets("DI").Select
Columns("a:aa").Select
Selection.AutoFilter
Selection.AutoFilter field:=2, Criteria1:="Cloturée", Operator:=xlOr, _
Criteria2:="Rejetée"
Selection.AutoFilter field:=6, Criteria1:=Bt
If dom <> "" And loc1 = "" And catloc = "" And Dat = "" And dat1 = "" Then
'choix sur bat et domaine
Selection.AutoFilter field:=8, Criteria1:=dom
' Call mise_en_page
ElseIf loc1 <> "" And dom = "" And catloc = "" And Dat = "" And dat1 = ""
Then 'choix sur bat et local
Selection.AutoFilter field:=7, Criteria1:="=" & loc1 & "***", Operator:=xlAnd
' Call mise_en_page
ElseIf catloc <> "" And dom = "" And loc1 = "" And Dat = "" And dat1 = ""
Then 'choix sur bat et categaorie local
If catloc = "BU" Then
Selection.AutoFilter field:=7, Criteria1:="<>*exloc"
End If
Selection.AutoFilter field:=7, Criteria1:="=" & "******" & catloc,
Operator:=xlAnd
ElseIf Dat <> "" And dom = "" And loc1 = "" And catloc = "" Then ' choix
sur bat et date

If Dat <> "" Then
date1 = DateSerial(Right(Dat.Value, 4), Mid(Dat.Value, 3, 2),
Left(Dat.Value, 2))
Range("ae1").Value = Dat
Range("ae1") = Format(Dat, "DD/MM/YYYY")
End If
If dat1 <> "" Then
date2 = DateSerial(Right(dat1.Value, 4), Mid(dat1.Value, 3, 2),
Left(dat1.Value, 2))
Range("af1").Value = dat1
Range("af1") = Format(dat1, "DD/MM/YYYY")
ElseIf Dat <> "" And dat1 = "" Then
date2 = Date
Range("af1").Value = date2
Range("af1") = Format(date2, "DD/MM/YYYY")
End If
date3 = Range("ae1").Value
date4 = Range("af1").Value


Selection.AutoFilter field:=20, Criteria1:=">=" & DateValue(date3),
Operator:=xlOr, _
Criteria2:="<=" & DateValue(date4)
Range("ae1:af1").ClearContents
End If






en plus j'ai essaye pas mal de d'astuces trouver ici mais rien n'y fait
alors HELP HELP dite mois SVP ou est mon erreur car la je CRAAAAAAQUE!!!!!!!

nb: toutes les valeurs inclus dans la feuille sont issue d'un query extrait
d'une base en oracle!!!!

1 réponse

Avatar
michdenis
Bonjour Christophe,

Pour pouvoir utiliser l'opérateur "=" sur un champ date, le format des dates dans ta plage de cellules doit avoir obligatoirement un
"format court" du type "25/05/05" tel que définit dans le panneau de configuration de windows. Tu pourras alors utiliser ceci :

Et comme excel est très capricieux sur le format date utilisé, le moyen que je trouve le plus facile est d'utiliser les "#" en début
et fin de la date. SEULEMENT n'oublie pas d'inverser jour/mois/année pour mois/jour/année

'------------------------
Dim D As Date
D = #11/16/2005#

With Range("A1:A50")
.AutoFilter field:=1, Criteria1:=D
End With
'------------------------



Salutations!




"christophe" a écrit dans le message de news:
bonjour a tous,

petite question pour vous les spécialistes!!!!

j'ai un filtre sur date en vba mais quand je lance la macro il me transforme
les valeur de dates en chiffres et donc il ne trouve rien!

voici le code:

Dim cir(6) As String, Bt As String, Rg As Range
Dim exloc()
Dim date1 As Date
Dim date2 As Date
Dim date3 As Date
Dim date4 As Date

loc1 = UCase(Loc)
exloc = Array("CI", "EX", "ES", "LT", "PA", "RE", "SA", "SR", "ST",
"TO", "VR")
If bat.Value = "Goldbell II" Then
Bt = "GOL"
ElseIf bat.Value = "KAD" Then
Bt = "KAD"
ElseIf bat.Value = "Tour A" Then
Bt = "TOA"
ElseIf bat.Value = "Tour B" Then
Bt = "TOB"
ElseIf bat.Value = "Schuman" Then
Bt = "SCH"
ElseIf bat.Value "Senningerberg" Then
Bt = "SEN"
End If
Sheets("DI").Select
Columns("a:aa").Select
Selection.AutoFilter
Selection.AutoFilter field:=2, Criteria1:="Cloturée", Operator:=xlOr, _
Criteria2:="Rejetée"
Selection.AutoFilter field:=6, Criteria1:=Bt
If dom <> "" And loc1 = "" And catloc = "" And Dat = "" And dat1 = "" Then
'choix sur bat et domaine
Selection.AutoFilter field:=8, Criteria1:=dom
' Call mise_en_page
ElseIf loc1 <> "" And dom = "" And catloc = "" And Dat = "" And dat1 = ""
Then 'choix sur bat et local
Selection.AutoFilter field:=7, Criteria1:="=" & loc1 & "***", Operator:=xlAnd
' Call mise_en_page
ElseIf catloc <> "" And dom = "" And loc1 = "" And Dat = "" And dat1 = ""
Then 'choix sur bat et categaorie local
If catloc = "BU" Then
Selection.AutoFilter field:=7, Criteria1:="<>*exloc"
End If
Selection.AutoFilter field:=7, Criteria1:="=" & "******" & catloc,
Operator:=xlAnd
ElseIf Dat <> "" And dom = "" And loc1 = "" And catloc = "" Then ' choix
sur bat et date

If Dat <> "" Then
date1 = DateSerial(Right(Dat.Value, 4), Mid(Dat.Value, 3, 2),
Left(Dat.Value, 2))
Range("ae1").Value = Dat
Range("ae1") = Format(Dat, "DD/MM/YYYY")
End If
If dat1 <> "" Then
date2 = DateSerial(Right(dat1.Value, 4), Mid(dat1.Value, 3, 2),
Left(dat1.Value, 2))
Range("af1").Value = dat1
Range("af1") = Format(dat1, "DD/MM/YYYY")
ElseIf Dat <> "" And dat1 = "" Then
date2 = Date
Range("af1").Value = date2
Range("af1") = Format(date2, "DD/MM/YYYY")
End If
date3 = Range("ae1").Value
date4 = Range("af1").Value


Selection.AutoFilter field: , Criteria1:=">=" & DateValue(date3),
Operator:=xlOr, _
Criteria2:="<=" & DateValue(date4)
Range("ae1:af1").ClearContents
End If






en plus j'ai essaye pas mal de d'astuces trouver ici mais rien n'y fait
alors HELP HELP dite mois SVP ou est mon erreur car la je CRAAAAAAQUE!!!!!!!

nb: toutes les valeurs inclus dans la feuille sont issue d'un query extrait
d'une base en oracle!!!!