Macro that only filters the column with the current date

Anonymous321

New Member
Joined
Oct 12, 2021
Messages
32
Office Version
  1. 365
Platform
  1. Windows
Hi.
I'm wondering if there is a way to set up a macro button that, once clicked, only filters the column that has the current date (the table headings are the months of the year). I know how to set it up so it filters a certain month (copy and pasted below). But it would be nice that, rather than me changing the macro code every month it automatically changes every month

Sub Free_Feb()
'
' Free_Feb Macro
'

'
ActiveSheet.Range("$E$3:$L$8").AutoFilter Field:=2, Criteria1:="Free"
End Sub


This is an example of the table I plan on filtering

Jan-21Feb-21Mar-21Apr-21May-21Jun-21Jul-21Aug-21
FreeBusyBusyBusyBusyBusyBusyBusy
FreeFreeFreeFreeFreeFreeBusyBusy
FreeBusyBusyBusyBusyBusyBusyBusy
FreeBusyBusyBusyBusyBusyBusyBusy
FreeFreeFreeFreeFreeFreeFreeFree
 
Then you could try these

VBA Code:
Sub Free_This_Month()
  Range("B3", Cells(3, Columns.Count).End(xlToLeft)).AutoFilter Field:=DateDiff("m", DateSerial(2021, 10, 1), Date) + 1, Criteria1:="Free"
End Sub

Sub Free_Next_Month()
  Range("B3", Cells(3, Columns.Count).End(xlToLeft)).AutoFilter Field:=DateDiff("m", DateSerial(2021, 10, 1), Date) + 2, Criteria1:="Free"
End Sub
 
Upvote 0
Solution

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Then you could try these

VBA Code:
Sub Free_This_Month()
  Range("B3", Cells(3, Columns.Count).End(xlToLeft)).AutoFilter Field:=DateDiff("m", DateSerial(2021, 10, 1), Date) + 1, Criteria1:="Free"
End Sub

Sub Free_Next_Month()
  Range("B3", Cells(3, Columns.Count).End(xlToLeft)).AutoFilter Field:=DateDiff("m", DateSerial(2021, 10, 1), Date) + 2, Criteria1:="Free"
End Sub
Seems to work fine. I've tested if it would work in December, and all seems ok. Thanks, you were alot of help :)
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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