A macro to identify the month in another column and filter the data month in the other column.

nonono

Board Regular
Joined
Jul 25, 2018
Messages
59
As what the title said, if column "I" month shows the latest month which is month "May"
vPzyB4u.png




Make column "H" filter out only data month with "May" only...

ffMwNiy.png


:eek:
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Try this
- your dates may not look the same, but should still function correctly

My results:




With
- month selected in cell R1
- data in columns A:P
- Headers in row 1
- column I & H values are dates
- cell R1 value is a date

Paste code into sheet module (right-click sheet tab \ View Code \ paste code in window on right)
Code:
Sub MonthFilter()
    Dim rng As Range:       Set rng = ActiveSheet.Range("A:P")
    Dim MyCriteria:         MyCriteria = GetDatesInPeriodConst(month(Range("R1")))
    On Error Resume Next
    rng.Parent.ShowAllData
    rng.AutoFilter field:=9, Criteria1:=MyCriteria, Operator:=xlFilterDynamic
    rng.AutoFilter field:=8, Criteria1:=MyCriteria, Operator:=xlFilterDynamic
End Sub

Function GetDatesInPeriodConst(month As Long)
    GetDatesInPeriodConst = 20 + month
End Function
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,952
Members
449,095
Latest member
nmaske

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