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: 12) 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