Excel: Autofilter between two times: Easier than it sounds

I'm fairly certain that this has to be a formatting issue of some kind. When stepping through the code, it correctly identifies "TimeToSearch1" and "TimeToSearch2" as the times to filter for.

With Worksheets("PII Yields")
        If .FilterMode Then .Range("A2:F2").AutoFilter
        .Range("A2:F2").AutoFilter Field:=1, _
                    Criteria1:=">=" & TimeToSearch1, _
                    Operator:=xlAnd, _
                    Criteria2:="<=" & TimeToSearch2
End With
I have formatted the Target Times to match the formatting on the spreadsheet I'm trying to manipulate but it doesn't seem to make any difference. The Target Times show as time only, while the spreadsheet shows a date/time combination. So, I'm guessing that I need to somehow change the formatting at one end or the other so that they finally match. Just not sure how to get there. There are a couple of steps before this filter process which may have something to do with the issue: 1. Filter spreadsheet by selected date. 2. Copy results and paste to new sheet as Values. 3. Format Column A (Dates) to .Range("A:A").NumberFormat = "HH:MM;@" Thanks for your time...

This question generated 11 answers. To proceed to the answers, click here.

This thread is current as of November 17, 2014.

For more resources for Microsoft Excel