How to add the ability to filter the column with several words to the following code?

shafiey

Board Regular
Joined
Sep 6, 2023
Messages
60
Office Version
  1. 365
Platform
  1. Windows
Criteria1 (cell D1) has multiple words separated by commas and I want the column in the "Projects" sheet to be filtered by these words.
How to add the ability to filter the column with several words to the following code?
Data sheet is in "Projects" sheet and in table= "projectstbl" and Data column= AC column, Field= 29, Header=1st row, Table Range= A2:AQ2100
Criteria is in "keywords analysis" sheet, D1 cell.
Thank you.

VBA code:

VBA Code:
Sub Filtering_AC_v2()
  
  Dim namebakhsh As String
  
  namebakhsh = Worksheets("Keywords Analysis").Range("D1").Value
  Application.Calculation = xlCalculationManual
  With Worksheets("Projects")
    .AutoFilterMode = False
    .Range("A1:AQ" & .Cells(.Rows.Count, "AC").End(xlUp).Row).AutoFilter Field:=29, Criteria1:=namebakhsh
  End With
  Application.Calculation = xlCalculationAutomatic
End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
VBA Code:
        .Range("A1:AQ" & .Cells(.Rows.Count, "AC").End(xlUp).Row).AutoFilter Field:=29, Criteria1:=Split(namebakhsh, ","), Operator:=xlFilterValues
 
Upvote 0
Solution
VBA Code:
        .Range("A1:AQ" & .Cells(.Rows.Count, "AC").End(xlUp).Row).AutoFilter Field:=29, Criteria1:=Split(namebakhsh, ","), Operator:=xlFilterValues
Thank you very very much
 
Upvote 0
Not to gainsay what John W offered, but I noticed you said it was in a table (and also, I dummied up a workbook to try and solve this, so I'm going to post my message anyways in hopes that it helps).

Here's my suggestion:

VBA Code:
Sub MultiFilter()
'Crafted by Wookiee at MrExcel.com


Dim wkbMe As Workbook
Dim objTable As Object

Set wkbMe = ThisWorkbook
Dim rngFilter As Range

Set rngFilter = wkbMe.Sheets("Keyword Analysis").Range("D21")
Set objTable = wkbMe.Sheets("Projects").ListObjects("projectstbl")

Dim vArray As Variant

vArray = VBA.Split(rngFilter.Formula, ",")

With objTable.Range

.AutoFilter _
    Field:=29, _
    Criteria1:=Array(vArray), _
    Operator:=xlFilterValues
End With

End Sub
 
Upvote 0
Not to gainsay what John W offered, but I noticed you said it was in a table (and also, I dummied up a workbook to try and solve this, so I'm going to post my message anyways in hopes that it helps).

Here's my suggestion:

VBA Code:
Sub MultiFilter()
'Crafted by Wookiee at MrExcel.com


Dim wkbMe As Workbook
Dim objTable As Object

Set wkbMe = ThisWorkbook
Dim rngFilter As Range

Set rngFilter = wkbMe.Sheets("Keyword Analysis").Range("D21")
Set objTable = wkbMe.Sheets("Projects").ListObjects("projectstbl")

Dim vArray As Variant

vArray = VBA.Split(rngFilter.Formula, ",")

With objTable.Range

.AutoFilter _
    Field:=29, _
    Criteria1:=Array(vArray), _
    Operator:=xlFilterValues
End With

End Sub
This code also worked well, thank you very much.
 
Upvote 0
Not to gainsay what John W offered, but I noticed you said it was in a table (and also, I dummied up a workbook to try and solve this, so I'm going to post my message anyways in hopes that it helps).

Here's my suggestion:

VBA Code:
Sub MultiFilter()
'Crafted by Wookiee at MrExcel.com


Dim wkbMe As Workbook
Dim objTable As Object

Set wkbMe = ThisWorkbook
Dim rngFilter As Range

Set rngFilter = wkbMe.Sheets("Keyword Analysis").Range("D21")
Set objTable = wkbMe.Sheets("Projects").ListObjects("projectstbl")

Dim vArray As Variant

vArray = VBA.Split(rngFilter.Formula, ",")

With objTable.Range

.AutoFilter _
    Field:=29, _
    Criteria1:=Array(vArray), _
    Operator:=xlFilterValues
End With

End Sub
Thank you for your effort,
If I want to use the greater than, smaller and equal sign in this code, how should I write it?
Similar to this code:

Criteria1:=">=" & Array(vArray), _
V‌BA code:

VBA Code:
Sub Filter_saleshoroo()
     'Crafted by Wookiee at MrExcel.com


Dim wkbMe As Workbook
Dim objTable As Object

Set wkbMe = ThisWorkbook
Dim rngFilter As Range

Set rngFilter = wkbMe.Sheets("Keywords Analysis").Range("H1")
Set objTable = wkbMe.Sheets("Projects").ListObjects("projectstbl")

Dim vArray As Variant

vArray = VBA.Split(rngFilter.Formula, ", ")

With objTable.Range

.AutoFilter _
    Field:=32, _
    Criteria1:=Array(vArray), _
    Operator:=xlFilterValues
End With
End Sub
 
Upvote 0
VBA Code:
        .Range("A1:AQ" & .Cells(.Rows.Count, "AC").End(xlUp).Row).AutoFilter Field:=29, Criteria1:=Split(namebakhsh, ","), Operator:=xlFilterValues
I think the Wookiee are sleeping.
Please, if possible, guide me in the problem of post #6.
sincerely
 
Upvote 0
Thank you for your effort,
If I want to use the greater than, smaller and equal sign in this code, how should I write it?
Similar to this code:


V‌BA code:

VBA Code:
Sub Filter_saleshoroo()
     'Crafted by Wookiee at MrExcel.com


Dim wkbMe As Workbook
Dim objTable As Object

Set wkbMe = ThisWorkbook
Dim rngFilter As Range

Set rngFilter = wkbMe.Sheets("Keywords Analysis").Range("H1")
Set objTable = wkbMe.Sheets("Projects").ListObjects("projectstbl")

Dim vArray As Variant

vArray = VBA.Split(rngFilter.Formula, ", ")

With objTable.Range

.AutoFilter _
    Field:=32, _
    Criteria1:=Array(vArray), _
    Operator:=xlFilterValues
End With
End Sub
Hi, Please, if possible, guide me in the problem of post #6.
sincerely
 
Upvote 0
I think the Wookiee are sleeping.
Please, if possible, guide me in the problem of post #6.
sincerely
Wookiee participates in this forum on his own free time and at his leisure. ;)

Your question as you asked it was answered. You have an entirely different question now, so I encourage you to post it as such.
 
Upvote 0

Forum statistics

Threads
1,215,110
Messages
6,123,138
Members
449,098
Latest member
Doanvanhieu

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