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
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Do you mean something like this?

VBA Code:
Sub Free_This_Month()
  ActiveSheet.Range("$E$3:$P$8").AutoFilter Field:=Month(Date), Criteria1:="Free"
End Sub
 
Upvote 0
Do you mean something like this?

VBA Code:
Sub Free_This_Month()
  ActiveSheet.Range("$E$3:$P$8").AutoFilter Field:=Month(Date), Criteria1:="Free"
End Sub
Worked a charm, thanks :). Any idea what i need to replace in this code if I had a button that filtered the next month, rather than the current
 
Upvote 0
Worked a charm, thanks :). Any idea what i need to replace in this code if I had a button that filtered the next month, rather than the current
SOLVED: I just did the same formula but added a "+ 1" after the closing bracket next to 'date' and before the comma.
 
Upvote 0
SOLVED: I just did the same formula but added a "+ 1" after the closing bracket next to 'date' and before the comma.
What if the current month is December? Which column would you then want filtered for "next month"?
 
Upvote 0
What if the current month is December? Which column would you then want filtered for "next month"?
Good question. I would want January 2022 filtered, but obviously this wouldn't work using the +1 method. Any ideas?
 
Upvote 0
I deleted that other spreadsheet as it was just an example, but this is what it would look like if I added dates after December. Jan 2022 is column E in this spreadsheet
Oct.2021​
Nov.2021​
Dec.2021​
Jan.2022​
Feb.2022​
Mar.2022​
FreeFreeFreeFreeFreeFree
BusyBusyBusyBusyFreeFree
BusyBusyBusyBusyFreeFree
BusyFreeFreeFreeFreeFree
BusyBusyBusyBusyFreeFree

Plus: That original code wont work if the table doesn't start with January which might become a problem in later months
 
Upvote 0
Does the column position change over time or will October 2021 always be in B?
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,497
Members
448,967
Latest member
visheshkotha

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