[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Filter on Date and time

Posted on 2010-09-02
15
Medium Priority
?
383 Views
Last Modified: 2012-05-10
Hello,

I have slightly tricky filter problem in Excel 2007.

I have a filter which filters on the previous days date.  For example, if today is 02/09/2010, the filter would show the data for 01/09/2010.  Unfortunately, the data imported have a time stamp included with the date.

I would like a filter which would filter from midnight at the start of the previous day until the end of the previous day.  

If the following filter was applied:
    ActiveSheet.Range("$A$1:$H$5000").AutoFilter Field:=1, Operator:=xlFilterValues, Criteria1:=Date - 1, Criteria2:=Time 00:00<=23:59

the data displayed would be:

01/09/2010 00:03
01/09/2010 19:00
01/09/2010 23:43

Thanks in advance.
0
Comment
Question by:Sonia Bowditch
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 2
  • +1
15 Comments
 
LVL 12

Expert Comment

by:tilsant
ID: 33584780
Try this:

ActiveSheet.Range("$A$1:$H$5000").AutoFilter Field:=1, Operator:=xlFilterValues, Criteria2:=Array(2, Date - 1)



Tils
0
 
LVL 77

Expert Comment

by:peter57r
ID: 33584796
ActiveSheet.Range("$A$1:$H$5000).AutoFilter Field:=1, Operator:=xlAnd, Criteria1:=">=" & Format(Date - 1, "yyyy-mm-dd"), Criteria2:="<" & Format(Date, "yyyy-mm-dd")
End Sub
0
 

Author Comment

by:Sonia Bowditch
ID: 33584877
Sorry guys,

I couldn't get either to work.

Tilsant, your solution did not show any records when the filter was applied.

peter57r, your solution had a compile error.  The message was "Expected: list seperator or )" on "yyyy-mm-dd".

Thanks
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 12

Expert Comment

by:tilsant
ID: 33584897
Can u post a sample data file?
Is your data having Column A with date values?
Is there any date with yesterday's date??
0
 
LVL 77

Accepted Solution

by:
peter57r earned 600 total points
ID: 33584925
Sorry there is a " missed in the address:

ActiveSheet.Range("$A$1:$H$5000").AutoFilter Field:=1, Operator:=xlAnd, Criteria1:=">=" & Format(Date - 1, "yyyy-mm-dd"), Criteria2:="<" & Format(Date, "yyyy-mm-dd")
0
 

Author Comment

by:Sonia Bowditch
ID: 33585346
Hello Tilsant,

Column A has data with date and time values and yes there is data with yesterday's date.  The following is contained in column A:

27/08/2010 07:02
27/08/2010 07:02
27/08/2010 07:02
27/08/2010 07:02
27/08/2010 07:02
27/08/2010 07:02
27/08/2010 07:02
27/08/2010 07:02
27/08/2010 07:03
27/08/2010 07:03
27/08/2010 07:03
27/08/2010 07:03
27/08/2010 07:03
27/08/2010 07:03
27/08/2010 07:03
27/08/2010 07:03
27/08/2010 07:03
27/08/2010 07:03
27/08/2010 07:04
27/08/2010 07:04
27/08/2010 07:04
27/08/2010 07:04
27/08/2010 07:04
27/08/2010 07:04
27/08/2010 07:04
27/08/2010 07:04
27/08/2010 07:04
31/08/2010 12:42
31/08/2010 12:42
01/09/2010 09:33
01/09/2010 09:33
01/09/2010 09:33
01/09/2010 09:33
01/09/2010 09:33
01/09/2010 09:33
01/09/2010 09:33
01/09/2010 09:33
01/09/2010 09:33
01/09/2010 09:33
01/09/2010 09:33
01/09/2010 09:33
01/09/2010 09:33

Thanks.
0
 
LVL 93

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 400 total points
ID: 33585424
Both of these seem to work.  I have not tried the other suggestions.
Sub test()
    
    With ActiveSheet.[a1]
        .AutoFilter
        .AutoFilter Field:=1, Criteria1:=xlFilterYesterday, Operator:=xlFilterDynamic
    End With
    
End Sub

Sub test2()
    
    With ActiveSheet.[a1]
        .AutoFilter
        .AutoFilter Field:=1, Criteria1:=">=" & Date - 1, Operator:=xlAnd, Criteria2:="<" & Date
    End With
    
End Sub

Open in new window

0
 
LVL 12

Expert Comment

by:tilsant
ID: 33585597
Try this one!

ActiveSheet.Range("$A$1:$H$5000").AutoFilter Field:=1, Operator:=xlFilterValues, Criteria2:=Array(2, Format((Date - 1), "dd/mm/yyyy"))



Tils
0
 

Author Closing Comment

by:Sonia Bowditch
ID: 33585599
Thanks guys.

matthewspatrick, your first solution worked perfectly but your second returned no results.

peter57r, your solution worked perfectly and I have incorporated it into my macro.

Thanks for everyone's help.
0
 

Author Comment

by:Sonia Bowditch
ID: 33585614
Sorry tilsant,  I didn't spot your solution until I had closed the question.

0
 
LVL 12

Expert Comment

by:tilsant
ID: 33585630
Did my last solution work for you??

I guess there was some conflict with the Date Format in VBA and Excel!
0
 
LVL 12

Expert Comment

by:tilsant
ID: 33585637
And that might be the reason why matthewspatrick's 2nd solution didn't work for you!
0
 

Author Comment

by:Sonia Bowditch
ID: 33585649
Hello tilsant,

Unfortunately your solution did not return any records. I agree with your assessment regarding a possible conflict.

Thank you very much for your time and effort.
0
 
LVL 12

Expert Comment

by:tilsant
ID: 33585694
Thats ok infosec36. Points aren't a big concern here for me!


Tils
0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 33587012
Almost certainly a formatting conflict :)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question