Solved

Autofilter equal to or less than today?

Posted on 2014-02-25
6
414 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

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 500 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Modify to work without control shift enter 9 33
Access 2010 7 44
Hash on Excel 13 43
Slicers by Groups in Excel 7 20
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

749 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