Adding cell contents to an array reference in macro

KibblesJack

New Member
Joined
May 25, 2022
Messages
4
Office Version
  1. 365
Platform
  1. Windows
After years of using base excel, I am just now learning how to use VBA to make my work process more efficient. I run weekly reports showing last weeks data, the financial weeks run Monday to Sunday. The data I pull contains data from the day I pull it, I don't want to include this data. I want to make my code reference a cell that contains the date I run the report so it can filter by this date and remove the data from the day I run the report. The "5/16/2022" date is what I want to change to be a cell reference that contains the current date. If this is not clear, please let me know.

VBA Code:
ActiveSheet.Range("$A$1:$S$65000").AutoFilter Field:=18, Criteria1:=Array( _
        "="), Operator:=xlFilterValues, Criteria2:=Array(2, [COLOR=rgb(250, 197, 28)]"5/16/2022"[/COLOR])
    Range("A2081:S65000").Select
    Selection.ClearContents
    ActiveSheet.Range("$A$1:$S$65000").AutoFilter Field:=18
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Have to think "5/16/2022" part would be Criteria2:=Array(2, Range("A2")).Value or whatever your cell address is.
 
Upvote 0
Solution

Forum statistics

Threads
1,223,893
Messages
6,175,246
Members
452,623
Latest member
cliftonhandyman

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