most recent date for auto filter within macro

ultratch47

Board Regular
Joined
Aug 6, 2002
Messages
126
This is my Macro

Range("E1").Select
Selection.AutoFilter
Selection.AutoFilter Field:=5, Criteria1:="1/2/2004"

i want the Criteria for the Auto Filter to always be the most recent date listed in Column E (this will always change)

i was thinking maybe we could use formula to pick out the recent date and list that in a cell, in turn listing the criteria as that cell

any helpful suggestions?
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
One way among several...modify for format of your column E dates:

Sub Test1()
Application.ScreenUpdating = False
ActiveSheet.AutoFilterMode = False
Dim myDate As Date
myDate = Application.Max(Columns(5))
Columns(5).AutoFilter Field:=1, Criteria1:="=" & Format(myDate, "mm/dd/yy")
Application.ScreenUpdating = True
End Sub
 
Upvote 0
from reading the macro, it appears user input is needed, i was hoping to stray away from that...

as this is a very long macro that will do a lot of dirty work by just clicking play.
 
Upvote 0
You obviously did not test the macro, there is no user input required, unless you want someone to click the button for you that the macro is attached to.
 
Upvote 0
i posted first then tested...
sorry for the assumption

the list in the column ranges down to row 745
after the macro the auto filter displays the column with cells 1:745 as hidden

therefor making the entire sheet appear blank
i'm not sure where the macro is lacking but thinks for the help
 
Upvote 0
actually its weird, the auto filter DOES work, and the most recent date is "HIGHLIGHTED" however the sheet does not display the results of this auto filter, by dropping the menu and re-highlighting, the auto filer works...
 
Upvote 0
The macro works and it tested fine for me based on your description. Are the dates formatted the same in column E, and did you make sure that the formatting they are in in column E is what the macro has them assumed to be on the Format line? That was what I meant by modifying the macro for date format. We could force the issue by formatting column E as a certain date format but I assumed you would want control over the spreadsheet formatting, and have the macro adhere to that.
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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