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!


[TABLE="width: 316"]
<colgroup><col></colgroup><tbody>[TR]
[TD]8/17/2014 6:22[/TD]
[/TR]
[TR]
[TD]3/1/2015 6:10[/TD]
[/TR]
[TR]
[TD]11/29/2015 21:53[/TD]
[/TR]
[TR]
[TD]6/2/2016 13:12[/TD]
[/TR]
[TR]
[TD]6/9/2017 15:19[/TD]
[/TR]
[TR]
[TD]10/21/2017 9:51[/TD]
[/TR]
</tbody>[/TABLE]
>=30
31>=60
61>=90
91>=
 

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.
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?

[TABLE="width: 316"]
<tbody>[TR]
[TD="class: xl63, width: 316"]11/25/2017 9:23[/TD]
[/TR]
</tbody>[/TABLE]
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,223,911
Messages
6,175,326
Members
452,635
Latest member
laura12345

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