VBA is not filtering date when i am using a date - 14

Anonymous
2022-07-11T06:56:21+00:00

Hello experts,

I have a dataset in which I have a date column which i want to filter and the basis of that filter is "is before or equal to for today i.e. in vba date -14" and this filter is not working properly. I also try to store this value in a variable and then i tried to use it filter but nothing works.

I am pasting a screenshot for my code

And when i run this code the result is blank

Microsoft 365 and Office | Excel | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes
Answer accepted by question author
  1. Andreas Killer 144K Reputation points Volunteer Moderator
    2022-07-11T07:07:19+00:00

    For dates you need to convert the argument into a number.

    Andreas.

    Sub Test()
    Range("A1").CurrentRegion.AutoFilter 4, "<" & CLng(Date - 14)
    End Sub

    11 people found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2022-07-11T07:08:51+00:00

    Thanks for the help it resolved now

    0 comments No comments