New Excel Forum

This forum has been moved to TeachExcel.com

Ask all future questions in the New Excel Forum.

ExcelKey

Macro to autofilter x days before Max date

Macros, VBA, Excel Automation, etc.

Macro to autofilter x days before Max date

Postby ziyan89 » Sat Dec 19, 2015 12:04 am

My current VBA module is below which only filter the Max Date, but I need to add in another criteria to filter both Max date and x days before Max date

Code: Select all
Sub Test1()
Application.ScreenUpdating = False
ActiveSheet.AutoFilterMode = False
Dim myDate As Date
myDate = Application.Max(Columns(1))
Columns(1).AutoFilter Field:=1, Criteria1:="=" & Format(myDate, "d-mmm-yy")

Application.ScreenUpdating = True
End Sub


Thank you for your kind help
  • 0

ziyan89
Rookie
 
Posts: 1
Joined: Dec 19, 2015
Reputation: 0
Excel Version: 2010

Re: Macro to autofilter x days before Max date

Postby pecoflyer » Sat Dec 19, 2015 3:13 am

Hi and welcome.
As you can see on your screen there is some text in red fonts asking to wrap code with code tags.
I will do it for you this time.
Please take a moment to read forum rules.

Thank you
  • 0

A relevant topic title helps get faster and more answers
pecoflyer
Moderator
 
Posts: 1274
Joined: Jan 24, 2012
Location: Belgium
Reputation: 39
Excel Version: 2003/2007/2010


Return to Macros and VBA Questions

Who is online

Users browsing this forum: No registered users and 233 guests