Filter Data Last 30, 60, 90 Days

treopro001

New Member
Joined
Nov 26, 2017
Messages
8
Hi Everyone,

Can someone point me in the direction on how to filter dates: In my excel sheet i have a list of users with the last logon time.
I would like to see/filter users on the last 30 days or before, Between 31-60 Days ago, and 60-90 days or more?



Username: LastLogonTime
BartSimpson 11/25/2015
HomerSimpson 3/1/2015
MargeSimpson 11/29/2017
Lisa Simpson 09/14/2017


Thanks for any help!


8/17/2014 6:22
3/1/2015 6:10
11/29/2015 21:53
6/2/2016 13:12
6/9/2017 15:19
10/21/2017 9:51

<colgroup><col></colgroup><tbody>
</tbody>
>=30
31>=60
61>=90
91>=
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Appologies for the typo please refer to this:

Hi Everyone,

Can someone point me in the direction on how to filter dates: In my excel sheet i have a list of users with the last logon time.
I would like to see/filter users on the last 30 days or before, Between 31-60 Days ago, and 60-90 days or more?



Username: LastLogonTime
BartSimpson 11/25/2015
HomerSimpson 3/1/2015
MargeSimpson 11/29/2017
Lisa Simpson 09/14/2017


Thanks for any help!
 
Upvote 0
It might help if you stated what your ranges are. The codes below for your first 2 critria in your first post are based on the range of dates being in column A, header in cell A1, Lookup date in B1. Adjust the ranges to suit.

Code:
Sub less30()
Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row).AutoFilter 1, "<" & CLng(Range("B1") - 30)
End Sub
Code:
Sub less3060()
Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row).AutoFilter 1, "<=" & CLng(Range("B1") - 31), xlAnd, ">=" & CLng(Range("B1") - 60)
End Sub

The third you should be able to work out yourself based on the 2nd code above.
 
Upvote 0
It might help if you stated what your ranges are. The codes below for your first 2 critria in your first post are based on the range of dates being in column A, header in cell A1, Lookup date in B1. Adjust the ranges to suit.

Code:
Sub less30()
Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row).AutoFilter 1, "<" & CLng(Range("B1") - 30)
End Sub
Code:
Sub less3060()
Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row).AutoFilter 1, "<=" & CLng(Range("B1") - 31), xlAnd, ">=" & CLng(Range("B1") - 60)
End Sub

The third you should be able to work out yourself based on the 2nd code above.


Hi Mark,

I'm very beginner level in Excel. Can you show me how I can post the code you mentioned?
 
Upvote 0
And the below if you actually want the times taken into account (read my last post about the ranges).

Code:
Sub less30time()
Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row).AutoFilter 1, "<" & CDbl(Range("B1") - 30)
End Sub
Code:
Sub less3060time()
Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row).AutoFilter 1, "<=" & CDbl(Range("B1") - 30), xlAnd, ">=" & CDbl(Range("B1") - 60)
End Sub
 
Upvote 0
Hi Mark,

I'm very beginner level in Excel. Can you show me how I can post the code you mentioned?

Alt F11, Click view, click Code. Copy the code and paste in the window that appears. close VB editor.

To run... Alt F8,click macro name, click Run.
 
Last edited:
Upvote 0
Wow, I did't know something like this is in Excel! Pretty neat.

I followed the steps but when I ran Alt F8 to run the code, a window popped up. "Type Mismatch". I clicked Okay and nothing happened. =/
 
Upvote 0
Have you got real dates in your cells i.e. if you in an empty cell put the formula
=ISNUMBER(A5)
changing the 5 to one of the cells with a date do you get TRUE or FALSE?

Same with the cell with the lookup date and have you amended the ranges as instructed?
 
Last edited:
Upvote 0
Have you got real dates in your cells i.e. if you in an empty cell put the formula changing the 5 to one of the cells with a date do you get TRUE or FALSE?

Same with the cell with the lookup date and have you amended the ranges as instructed?

11/25/2017 9:23

<tbody>
</tbody>
In one of the cells I cleared that and typed =ISNUmber(A5) and got a False. Btw the data that was generated was from Powershell that I ran.
 
Upvote 0
Then your "dates" are text not real dates and you can't do a between with text.
If your Windows regional date settings are mm/dd/yyyy try selecting the column, click Data - Text to Columns, click Next twice, check that General is checked, click Finish.
Check that your formula has changed to TRUE.

Make sure your macro has been reset (VB editor-Tools - reset) and try again.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,520
Messages
6,114,101
Members
448,548
Latest member
harryls

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