Filtering Of Date Value Not Working

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I'm trying to apply a filter to a date column in my database, but the results are empty. Is someone able to suggest a correction to my code?

Code:
Sub StaffOnChange()
    Dim nWSName As String
    Dim wsSS As Worksheet
    Dim changeDate As Date
    
    nWSName = ActiveSheet.Name
    Set wsSS = Worksheets(nWSName)

    changeDate = wsHold.Range("B3")

    With wsSS
        If .AutoFilterMode Then .AutoFilterMode = False
        .Range("B3").AutoFilter Field:=1, Criteria1:=changeDate
        .AutoFilterMode = False
    End With
     
    wsSS.Delete
    
End Sub

The value changeDate = 2022-07-22, is a date, and can be accurately reformatted as 22-Jul-22 ("dd-mmm-yy").
The data in column A of worksheet wsSS are dates, represented as serials of that date. They can be accurately reformatted as "dd-mmm-yy".
In my testing, with changedate = 2022-07-22, the filter is not filtering out the row (72) in which A72 = 44764 (2022-07-22).
 
Thanks for the feedback.
When you use Match, as long as both the cell to find and the range to look in are actually stored as dates and not text, then Match will find it regardless of format. I have tried formatting the find date as a normal date in "dd/mm/yyyy" format and the range to look in as just "d" and Match will still find it.

Filter, Find Formulas and Find Values do care about format.
Even CLng which I thought to be the goto fix only worked for me when column A was formatted as general and not when I formatted it dd/mm/yyyy.
 
Upvote 0

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Very interesting and valuable tidbit of shared info Alex. I hope I can remember that to avoid asking the same question again two months down the road. Search is useful providing you know the appropriate terms to use.
 
Upvote 0

Forum statistics

Threads
1,214,851
Messages
6,121,931
Members
449,056
Latest member
denissimo

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