Filter Multiple Sheets based on single cell Value in VBA

willisom24

New Member
Joined
Nov 5, 2017
Messages
7
I have a workbook with an input sheet (sheet1) and multiple data sheets after that. Column X in each data sheet contains dates that are filtered. I have copied the following VBA code from another user to update the filters for the single date I want to filter in all sheets. It is as follows:

Sub apply_autofilter_across_worksheets()
Dim xWs As Worksheet
On Error Resume Next
For Each xWs In Worksheets
xWs.Range("x6").AutoFilter 1, "12/29/2017"
Next
End Sub

This macro is running well. What I want to change is the "12/29/2017". How can I instead have the macro pull the date from cell A3 of the input sheet (sheet1), rather than always having to update the date in the actual code each time? I will never need to filter more than one date at a time, so I will not need to use multiple criteria.

Any help would be greatly appreciated as I am a novice at VBA.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Since autofilter accepts only U.S. format date string, you need to format the date accordingly:
xWs.Range("x6").AutoFilter 1, Format(Sheets("Sheet1").Range("A3"), "mm\/dd\/yyyy")
 
Upvote 0
Or possibly.

Code:
xWs.Range("x6").AutoFilter 1, Clng(Sheets("Sheet1").Range("A3").Value)
 
Upvote 0
Thank you for taking the time to look at this issue. Unfortunately the 2 suggested solutions did not work when I tested them. Any other ideas?
 
Upvote 0

Forum statistics

Threads
1,215,480
Messages
6,125,050
Members
449,206
Latest member
Healthydogs

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