VBA Autofilter Dynamic Criteria

ChiefLapuLapu

New Member
Joined
Apr 7, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I am trying to figure out a way to make my autofilter criteria dynamic as it will change in the future. The criteria is a week ending date that will change in two week increments. So 3262022 will turn into 4092022 the next time I run the macro. Is there anyway to do this other than updating the code regularly?

Thanks in advance.

VBA Code:
ActiveSheet.Range("$A$1:$L$" & LR).AutoFilter Field:=8, Criteria1:= _
        "3262022"
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Use a variable instead of hardcoding the criteria.

VBA Code:
CriteriaStr = "3262022"

ActiveSheet.Range("$A$1:$L$" & LR).AutoFilter Field:=8, Criteria1:=CriteriaStr
 
Upvote 0
You could put the date into a cell & have the macro look at that.
 
Upvote 0

Forum statistics

Threads
1,214,631
Messages
6,120,640
Members
448,974
Latest member
DumbFinanceBro

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