Select Filter between two dates

Nick70

Active Member
Joined
Aug 20, 2013
Messages
299
Office Version
  1. 365
Platform
  1. Windows
Hi,

I would like a code so that the filter selects dates between January 2024 and December 2024.
Data is in Sheet1 in range(A5:Z100)
Date filter is on column C

Which code can do that?

Thanks,
Nic :unsure:
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Using the new FILTER function, it would look like:
Excel Formula:
=FILTER(A5:Z100,YEAR(C5:C100)=2024)
 
Upvote 0
Not sure I understand this filter formula but I was looking for a VBA code to select filter for me automatically (so I do not have to do selection manually).

Txs,
Nic
 
Upvote 0
Excel 365 has a new FILTER function which makes this very easy (though it filters to a separate range). See: FILTER function - Microsoft Support.

Are you saying that you just want to apply the filters to the current data and "filter in place"?
Regarding your range (rows and columns), what can change and what must stay the same?
 
Upvote 0
Ok thanks.
Great formula but was looking for VBA code.

In answer to your questions:

Are you saying that you just want to apply the filters to the current data and "filter in place"? - YES
Regarding your range (rows and columns), what can change and what must stay the same? - Rows can change

Txs,
N.
 
Upvote 0
OK, I think this should do what you want:
VBA Code:
Sub MyFilterCode()

    Dim lr As Long
    Dim rng As Range
   
'   Find last row in column C with data
    lr = Cells(Rows.Count, "C").End(xlUp).Row
   
'   Set range to filter
    Set rng = Range("A4:Z" & lr)
   
'   Set filter
    rng.AutoFilter
    rng.AutoFilter Field:=3, Criteria1:=">=1/1/2024", Operator:=xlAnd, Criteria2:="<=12/31/2024"
       
End Sub
 
Upvote 0
Solution
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,215,102
Messages
6,123,097
Members
449,096
Latest member
provoking

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