VBA filtering

DBIO

New Member
Joined
Apr 13, 2023
Messages
1
Office Version
  1. 365
  2. 2021
  3. 2019
Platform
  1. Windows
Hi experts,


What I'm trying to complete is beyond my Excel-skills so you you guys can help.

I have a table, where i need to filter basically on four column, but the values on these I have textjoined with semicolon, collecting these values in one cell (in column AW). This value illustrated how many weeks there is until deadline.

I would like to create six (6) filters in VBA filters, to look in this column AW and do the following:
- First filter: If cell contains the value 0 or 1 (indicating deadline this week or next), show the rows.
- Second filter: If cell contains the value 0, 1 or 2(indicating deadline this week, next or the week after), show the rows.
- The next filters are with the same principals as above, just adding one extra week in the end.

My skills with VBA only allows me to filter with two criteria’s (which as I understand is also the normal limitation for this).

Do any of you have any ideas on how to approach this? Thanks in advance.
 

Attachments

  • 2023-04-13 15_18_00.png
    2023-04-13 15_18_00.png
    38.9 KB · Views: 8

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try:

VBA Code:
Sub ApplyFilters()

    Dim ws As Worksheet
    Dim tbl As ListObject
    Dim rng As Range
    Dim filterCriteria(1 To 6) As String
    
    filterCriteria(1) = "0;1"
    filterCriteria(2) = "0;1;2"
    filterCriteria(3) = "0;1;2;3"
    filterCriteria(4) = "0;1;2;3;4"
    filterCriteria(5) = "0;1;2;3;4;5"
    filterCriteria(6) = "0;1;2;3;4;5;6"
    
    Set ws = ThisWorkbook.Worksheets("Sheet1") ' Replace "Sheet1" with the name of your worksheet
    Set tbl = ws.ListObjects("Table1") ' Replace "Table1" with the name of your table
    Set rng = tbl.ListColumns("AW").DataBodyRange ' Replace "AW" with the column name of your range
    
    For i = 1 To 6
        tbl.Range.AutoFilter Field:=rng.Column, Criteria1:=Split(filterCriteria(i), ";"), Operator:=xlFilterValues
        ' Perform any additional operations you want to do here, such as copying the filtered data to another worksheet
    Next i
    
    tbl.Range.AutoFilter Field:=rng.Column

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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