Autofilter multiple sheets with manual date range

jflo714

New Member
Joined
Dec 7, 2017
Messages
3
I have a workbook that has multiple sheets from multiple linked datasources. I would like to have a Dashboard page that I am able to select a type a date range in B1 and C1 (start and end date) and it filter Column A in all of the other worksheets. I found the code below, but this looks at the Range(B1) and Range(C1) in their respective sheets not back to the "Dashboard" where the dates would have been set.

Sub apply_autofilter_across_worksheets()
'Updateby Extendoffice 20160623
Dim xWs As Worksheet
On Error Resume Next
For Each xWs In Worksheets
xWs.Range("A1").AutoFilter 1, Criteria1:=">=Range(B1)", Operator:=xlAnd, Criteria2:="<=Range(C1)"
Next
End Sub


Thanks for time in advance
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
If your dashboad is on Sheet1, eg. then
Code:
xWs.Range("A1").AutoFilter 1, Criteria1:=">=[COLOR=#FF0000]Sheets("Sheet1").[/COLOR]Range(B1)", Operator:=xlAnd, _
Criteria2:="<=[COLOR=#FF0000]Sheets("Sheet1").[/COLOR]Range(C1)"
 
Upvote 0
If your dashboad is on Sheet1, eg. then
Code:
xWs.Range("A1").AutoFilter 1, Criteria1:=">=[COLOR=#FF0000]Sheets("Sheet1").[/COLOR]Range(B1)", Operator:=xlAnd, _
Criteria2:="<=[COLOR=#FF0000]Sheets("Sheet1").[/COLOR]Range(C1)"


Thanks for quick help.

This code is giving a compile error "Expected: end of statement" after the first Sheets("Sheet1").

I originally had that Sheet named "Dashboard" but was throwing a syntax error so I renamed it to Sheet 1 and getting that error above.
 
Upvote 0
Try
Code:
xWs.Range("A1").AutoFilter 6, Criteria1:=">=" & Sheets("Sheet1").Range("B1") & "", Operator:=xlAnd, _
Criteria2:="<=" & Sheets("Sheet1").Range("C1") & ""
 
Upvote 0
Try
Code:
xWs.Range("A1").AutoFilter 6, Criteria1:=">=" & Sheets("Sheet1").Range("B1") & "", Operator:=xlAnd, _
Criteria2:="<=" & Sheets("Sheet1").Range("C1") & ""


That did it!

Thanks for the help, both of you!
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,013
Members
448,935
Latest member
ijat

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