If those values in column P are really dates...
This is from "Excel 2002 VBA Programmer's Reference"
Written by John Green, Stephen Bullen, Rob Bovey and Robert Rosenberg
http://www.oaltd.co.uk:80/ExcelProgR...rogRefCh22.htm
Search for "Range.AutoFilter" and you'll see this note:
Range.AutoFilter
The AutoFilter method of a Range object is a very curious beast. We are forced
to pass it strings for its filter criteria and hence must be aware of its string
handling behaviour. The criteria string consists of an operator (=, , <, =
etc.) followed by a value.
If no operator is specified, the "=" operator is assumed. The key issue is that
when using the "=" operator, AutoFilter performs a textual match, while using
any other operator results in a match by value. This gives us problems when
trying to locate exact matches for dates and numbers.
If we use "=", Excel matches on the text that is displayed in the cell, i.e. the
formatted number. As the text displayed in a cell will change with different
regional settings and Windows language version, it is impossible for us to
create a criteria string that will locate an exact match in all locales.
There is a workaround for this problem. When using any of the other filter
criteria, Excel plays by the rules and interprets the criteria string according
to US formats. Hence, a search criterion of "=02/01/2001" will find all dates
on or after 1st Feb, 2001, in all locales.
We can use this to match an exact date by using two AutoFilter criteria. The
following code will give an exact match on 1st Feb, 2001 and will work in any
locale:
Range("A1:D200").AutoFilter 2, "=02/01/2001", xlAnd, "<=02/01/2001"
So you may want (guessing because you didn't share what startfilter and
endfilter were):
Selection.AutoFilter Field:=16, _
Criteria1:="=" & format(startFilter, "mm/dd/yyyy")
Operator:=xlAnd, _
Criteria2:="<" & format(endFilter, "mm/dd/yyyy")
Bigfoot17 wrote:
I am having soem problems figuring out how to tackle a problem. I have been
successful in [1] autofiltering a spreadsheet; [2] selecting the filtered
data and [3] copying it to a new sheet where I further manipulate it.
However, I have found that when my autofilter finds no appropriate data (no
record between two dates) instead of getting zero records I instead get all
of the data copied.
Can someone shed light on this and point me in the proper direction? Here
is part of my selection and copy process:
dLrow = Cells(Rows.Count, "P").End(xlUp).Row
'Field:=16 is Column P(card expiration date), D(last name, C(first name)
Selection.AutoFilter Field:=16, Criteria1:="=" & startFilter,
Operator:=xlAnd _
, Criteria2:="<" & endFilter
Range("D3:D" & dLrow & ",E3:E" & dLrow & ",P3:P" & dLrow).Select
Selection.Copy
Workbooks.Add
Range("A2").Select
ActiveSheet.Paste
--
Dave Peterson