Использовать дату при применении автофильтра — Visual Basic(Бейсик)

'Вариант 1

Dim iDateOne As Date
Dim iDateTwo As Date
 
iDateOne = "08.09.2004"
iDateTwo = "08.10.2004"
 
iCriteria1 = ">=" & Format(iDateOne, "#")
iCriteria2 = "<=" & Format(iDateTwo, "#")
 
Range("A1").AutoFilter Field:=1, Criteria1:=iCriteria1, Operator:=xlAnd, Criteria2:=iCriteria2
Вместо Format(iDate, "#") можно использовать Format(iDate, "General Number")

'Вариант 2

iDateOne = #9/8/2004# ' "08.09.04"
iDateTwo = #10/8/2004# ' "08.10.04"

iCriteria1 = ">=" & CDbl(iDateOne)
iCriteria2 = "<=" & CDbl(iDateTwo)
 
Range("A1").AutoFilter Field:=1, Criteria1:=iCriteria1, Operator:=xlAnd, Criteria2:=iCriteria2

'Вариант 3

iDateOne = #9/8/2004# ' "08.09.04"
iDateTwo = #10/8/2004# ' "08.10.04"

With Application
     iCriteria1 = ">=" & .Text(iDateOne, "@")
     iCriteria2 = "<=" & .Text(iDateTwo, "@")
End With
 
Range("A1").AutoFilter Field:=1, Criteria1:=iCriteria1, Operator:=xlAnd, Criteria2:=iCriteria2

Leave a Comment