?
Solved

Autofilter equal to or less than today?

Posted on 2014-02-25
6
Medium Priority
?
429 Views
Last Modified: 2014-02-26
How do I write an autofilter that says =< today?

   ActiveSheet.RangeUsed.AutoFilter Field:=37, Operator:= _
    xlFilterValues, Criteria2:=Array(0, DateValue(Now) - 1)

Open in new window

0
Comment
Question by:RWayneH
[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
  • 3
  • 2
6 Comments
 
LVL 22

Expert Comment

by:Flyster
ID: 39887670
You can try:
   ActiveSheet.RangeUsed.AutoFilter Field:=37, Operator:= _
    xlFilterValues, Criteria2:="<=" & Array(0, DateValue(Now) ) 

Open in new window

Flyster
0
 

Author Comment

by:RWayneH
ID: 39887691
For some reason this is failing.  I forgot too that I need to take out the blanks and the #N/A's.  All I need to see are the cells that have dates and are =< today.
0
 
LVL 16

Expert Comment

by:Jerry Paladino
ID: 39887695
ActiveSheet.RangeUsed.AutoFilter Field:=37, Operator:= _
    xlFilterValues, Criteria2:="<=" & Format(Date, "m/d/yyyy")

This should eliminate blanks and #NA
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

Author Comment

by:RWayneH
ID: 39887712
Here is the sheet that I am trying to run the autofilter on and here is the code that is failing.

' Macro13 Macro
'Sheets("CDPSRECRPT-Yesterday").Select
    Rows("1:1").Select
    Selection.AutoFilter  'filter on
   
'    ActiveSheet.RangeUsed.AutoFilter Field:=37, Operator:= _
'    xlFilterValues, Criteria2:="<=" & Array(0, DateValue(Now))
    
    ActiveSheet.RangeUsed.AutoFilter Field:=37, Operator:= _
    xlFilterValues, Criteria2:="<=" & Format(Date, "m/d/yyyy")

    RowCnt2 = ActiveSheet.UsedRange.Columns(1).SpecialCells(xlVisible).Count
    Sheets("MOT-MeasureData").Select
    Range("C2").Select 'put the number complete in the previous day
    Range("C3") = RowCnt2  'places the number in MOT-MeasureData

'

End Sub

Open in new window

CDPS.xlsx
0
 
LVL 16

Accepted Solution

by:
Jerry Paladino earned 2000 total points
ID: 39887735
I believe it was failing because you had "RangeUsed" instead of "UsedRange".  
     ActiveSheet.UsedRange.AutoFilter Field:=37, _
    Criteria1:="<=" & Format(Date, "m/d/yyyy"), Operator:=xlFilterValues

Open in new window

Edited - Sorry - I copied the wrong one
0
 

Author Closing Comment

by:RWayneH
ID: 39888839
Thanks for the help. -R-
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

765 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