Hello,

I am new user on this forum, first of all, thanks very much for your attention.

I am trying to filter a column between two dates with their respective times.

For this i tried to transfer the "date" string to long and the "time" string into double, and then concatenate this two numbers sent them to the function Autofilter as the "criteria" parameter.

As I executed this code i was not getting any result, I stopped and looked at the excel file and i saw that the number is sent to the box without the "," that separates the date(integer number) and the time (fraction number).

Does anyone know hoa could i fix this problem?

Thanks very much for your time

Here is the code:


Sub Filtrar_entre_fechas()

Dim Dayfilter As Date
Dim Dayfilter2 As Date
Dim Shift1 As Date
Dim Shift2 As Date

Dim lFecha1 As Long, lFecha2 As Long
Dim dtime1 As Double, ddtime2 As Double
Dim ddatetime1 As Double
Dim ddatetime2 As Double

Dim prueba1 As String
Dim prueba2 As String


Dayfilter = "11/12/2012"
Dayfilter2 = "12/12/2012"
Shift1 = "7:00"
Shift2 = "15:00"

Range("R1") = Dayfilter
Range("R2") = Dayfilter2
Range("R3") = Shift1
Range("R4") = Shift2

lFecha1 = Range("R1")
lFecha2 = Range("R2")
dtime1 = Range("R3")
dtime2 = Range("R4")
ddatetime1 = lFecha1 + dtime1
ddatetime2 = lFecha2 + dtime2

prueba1 = Mid(dtime1, 2)
prueba2 = Mid(dtime2, 2)


With ActiveSheet
If .AutoFilterMode = True Then .AutoFilterMode = False
End With


Cells.Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$E$1903").AutoFilter Field:=1, Criteria1:="MicroparoB1100"
'ActiveSheet.Range("$A$1:$E$1903").AutoFilter Field:=2, Criteria1:=">=" & ddatetime1, Operator:=xlAnd, Criteria2:="<=" & ddatetime2
ActiveSheet.Range("$A$1:$E$1903").AutoFilter Field:=2, Criteria1:=">=" & lFecha1 & prueba1, Operator:=xlAnd, Criteria2:="<=" & lFecha2 & prueba2

End Sub