Eric Penfold
Active Member
- Joined
- Nov 19, 2021
- Messages
- 424
- Office Version
- 365
- Platform
- Windows
- Mobile
Please could you help as to why the filter will not work in this code. Need yesterdays & todays filtered.
VBA Code:
Sub FindValues()
Dim ws As Worksheet
Dim Rng As Range
Dim Lrow As Long, Yesterday As Long, ToDay As Long
Dim Comparerng As Variant, x As Variant, y As Variant, i As Variant
Dim Sourcerng As Range
Dim YDate As Date
Dim TDate As Date
On Error Resume Next
Set ws = ActiveSheet
Lrow = ws.Range("A2").End(xlDown).Row
Set Rng = ws.Range("A2:J" & Lrow)
ToDay = (DateSerial(Year(Date), Month(Date), Day(Date)))
TDate = ToDay
TDate = Format(TDate, "mm/dd/yyyy")
Yesterday = (DateSerial(Year(Date), Month(Date), Day(Date - 1)))
YDate = Yesterday
YDate = Format(YDate, "mm/dd/yyyy")
Rng.AutoFilter Field:=1, _
Criteria1:=">" & YDate, _
Operator:=xlAnd, _
Criteria2:="<" & TDate
End Sub