[VBA] Filter range based on separate range of cell values

StuckInWork

New Member
Joined
Jul 30, 2021
Messages
6
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
Platform
  1. Windows
Hi all, apologies I have not been able to find the solution with my searches despite trying multiple solutions.
My query is as below,

I have a sheet of data (data range A13:K2000), the A range is date, the range headers are in row 12.
I have 5 separate boxes (range B4:B9) with the dates ranged from Monday to Friday, entering the Monday date inputs the remaining dates.
Essentially I need the A range (dates) to apply filters based on the 6 cell values in range B4:B9 when the VBA is ran.

Thanks in advance.

1669650881489.png
 
Last edited by a moderator:

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Is this what you want?

VBA Code:
Option Explicit
Sub StuckInWork()
    Dim ws As Worksheet
    Set ws = Worksheets("Sheet1")
    
    With ws.Range("A12").CurrentRegion
        .AutoFilter 1, ">=" & CLng(ws.Range("B4")), 1, "<=" & CLng(ws.Range("B4") + 5)
    End With

End Sub

Before:
Book1
ABCD
3DATEEXCLUSIONS/TOTAL
4MONDAY28/11/20221/1
5TUESDAY29/11/20220/1
6WEDNESDAY30/11/20220/1
7THURSDAY01/12/20220/1
8FRIDAY02/12/20221/1
9SATURDAY03/12/20220/1
10
11
12DATEACCCUSTOMERRO
1328/11/202212345test1d
1429/11/202212346test2
1530/11/202212347test3
1601/12/202212348test4
1702/12/202212349test5
1803/12/202212350test6
1904/12/202212351test7
2005/12/202212352test8
2106/12/202212353test9
2207/12/202212354test10
2308/12/202212355test11
24
Sheet1
Cell Formulas
RangeFormula
B5:B9B5=B4+1


After:
Book1
ABCD
3DATEEXCLUSIONS/TOTAL
4MONDAY28/11/20221/1
5TUESDAY29/11/20220/1
6WEDNESDAY30/11/20220/1
7THURSDAY01/12/20220/1
8FRIDAY02/12/20221/1
9SATURDAY03/12/20220/1
10
11
12DATEACCCUSTOMERRO
1328/11/202212345test1d
1429/11/202212346test2
1530/11/202212347test3
1601/12/202212348test4
1702/12/202212349test5
1803/12/202212350test6
24
Sheet1
Cell Formulas
RangeFormula
B5:B9B5=B4+1
 
Upvote 0
Solution
Thanks for your help, the code you've provided doesn't work on a protected sheet but I can work around that.
 
Upvote 0

Forum statistics

Threads
1,214,588
Messages
6,120,412
Members
448,960
Latest member
AKSMITH

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