Filtering to find data created yesterday

polykid

New Member
Joined
Apr 27, 2012
Messages
6
Morning all,

Firstly, the version I'm using is Excel 2007.

I wrote a macro to filter my spreadsheets then copy and paste the relevant data into a new spreadsheet. The criteria used are: find all data created on the previous business day & find data that was either "new" or "updated" on that day.

Initially it worked fine but when I put it in my "live" spreadsheet, the filter now doesn't work as intended.

I have tried changing the date format & using data validation in the column containing the 2nd criteria. As the code didn't change prior to me placing it in the "live" sheet, I've concluded (rightly or wrongly) that the problem is with the spreadsheet rather than the code.

Anyway, the code is shown below. Thanks in advance for any help provided!

Code:
Sub dailystats()
'
' dailystats Macro
'

    Dim xDay As String
    Dim xDate As Date
    
    Application.ScreenUpdating = False
    Sheets("PAC").Activate
    Rows("1:1").Select
    selection.AutoFilter
 
    xDay = Format(Date, "dddd")
 
    If xDay = "Monday" Then
    xDate = Date - 3
    Else
    xDate = Date - 1
    End If
 
    ActiveSheet.Range("$A$1:$Z$399").AutoFilter Field:=1, Criteria1:=xDate
    ActiveSheet.Range("$A$1:$Z$399").AutoFilter Field:=3, Criteria1:="NEW", _
        Operator:=xlOr, Criteria2:="UPDATE"
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,216,101
Messages
6,128,843
Members
449,471
Latest member
lachbee

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top