Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Autofilter date column to rest of the upcoming months that comes after next month

0

I have a code that filters column A to next month using xlDynamicfilter operator.Next step is to filter the same column A to rest of the upcoming months that comes after next month.

Sheet1.Range("A1").CurrentRegion.AutoFilter Field:=1, field:=1, Operator:=xlFilterDynamic, Criteria1:=xlFilterNextMonth

For eg: if current month is july, above code filters date to august, likewise in the next step I need to filter dates to rest of the months that comes after august.

Is this possible in vba?

Answer
Discuss

Answers

0
Selected Answer

You should probably place your code in a sub that you call with a parameter where the argument is the month you want to filter by, i.e. Criteria1. The setup would be as shown below.

Sub Main()
    Dim Crit As Variant
    ' determine which month to call
    ' perhaps using an InputBox
    Crit = InputBox "Enter the month to filter by"
    FilterMyData Crit
    ' do things with the filtered data
End Sub

Private Sub FilterMyData(Crit As Variant()
    Sheet1.Range("A1").CurrentRegion.AutoFilter Field:=1, field:=1, Operator:=xlFilterDynamic, Criteria1:=Crit
End Sub
Discuss

Discussion

That helps.

Thanks Variatus!
Dr Liss (rep: 26) Aug 2, '20 at 1:19 pm
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login