AutoFilter Criteria in VBA
Hilvert; I dont think you have tried the code which I posted initially where
the variables are declared as *** Date ****
Please note the correction in references ....
Sub Macro()
Dim dtStart As Date, dtEnd As Date
dtStart = Range("C2")
dtEnd = Range("D2")
Selection.AutoFilter Field:=1, _
Criteria1:="" & dtStart, Operator:=xlAnd, _
Criteria2:="<=" & dtEnd
End Sub
If this post helps click Yes
---------------
Jacob Skaria
"Hilvert Scheper" wrote:
Dear Per and Jacob,
Many Thanks again to You Both for Your help,
Whatever I try, the filter Won't show the 225 entries that I need, "0
records found".
Very Frustrating, I think I'll just give up for now, looks like I'm not
getting anywhere with this.
Question; Why do You put "" in the first Criteria (without the "="?), and
"<=" in the second, is there any logic to this? Just curious that's all.
Kind Regards,
Hilvert
"Per Jessen" wrote:
Thanks for your reply,
Looking a bit closer to your filter statements, as you are trying to set up
two conditions for one column, it shall be done in one statement:
Selection.AutoFilter Field:=4, _
Criteria1:= "" & Crit1, _
Operator:=xlAnd, _
Criteria2:= "<=" & Crit2
Hopes this helps.
---
Per
"Hilvert Scheper" skrev i
meddelelsen ...
Dear Jacob and Per,
Thank You so much for Your ideas BUT...
The Filter still does not show anything; "0 Records of 1416 found", where
it
should show 225 records...
Sorry!!
Any ideas Please?
Rgds, Hilvert
"Per Jessen" wrote:
Hi
You are trying to filter for the text "'[Other File...." , not for the
value
in A3. Look at this:
Set wb = Workbooks("Other File.xls")
Set sh = wb.Worksheets("Sheet1")
Crit1 = sh.Range("A3").Value
Crit2 = sh.Range("A9").Value
Selection.AutoFilter Field:=4, Criteria1:= _
"" & Crit1, _
Operator:=xlAnd
Selection.AutoFilter Field:=4, Criteria1:= _
"<=" & Crit2, _
Operator:=xlAnd
Hopes this helps.
---
Per
"Hilvert Scheper" skrev i
meddelelsen ...
Hi There,
Can Anyone help me out here Please,
I want to Filter a spreadsheet by Two criteria that refer to values in
another workbook: Greater than the Date in Cell A3 and Less than the
Date
in
Cell A9.
How on earth can I do this? I tried:
Selection.AutoFilter Field:=4, Criteria1:= _
"'[Other File.xls]Sheet1'!$A$3", _
Operator:=xlAnd
Selection.AutoFilter Field:=4, Criteria1:= _
"<='[Other File.xls]Sheet1'!$A$9", _
Operator:=xlAnd
and this doesn't work. The Filter is on but isn't showing Any
entries...
I Really appreciate Your help!!
Rgds, Hilvert
|