Macro to filter out everything but a list of words

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone
I Sheet"Data" Range G6:G26" i have a list of words

In Sheet "Input" Range J10:J500 i have anothe list
I want a vba macro to filter "Input" Range J10:J500 to just show me the words in Sheet"Data" Range G6:G26"
please help if you can
Thanks
Tony
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
In a workseet formula rather than VBA, you could try this...
Excel Formula:
=FILTER(Input!J10:J500,ISNUMBER(MATCH(Input!J10:J500,Data!G6:G26,0)))
Hope that helps,

Doug
 
Upvote 0
This code assumes you have a header in J9 of the Input sheet.
VBA Code:
Sub FilterData()
    Application.ScreenUpdating = False
    Dim v As Variant, i As Long, arr() As Variant, x As Long
    v = Sheets("Data").Range("G6:G26").Value
    For i = LBound(v) To UBound(v)
        x = x + 1
        ReDim Preserve arr(1 To x)
        arr(x) = v(i, 1)
    Next i
    Sheets("Input").Range("J9").AutoFilter Field:=1, Criteria1:=arr, Operator:=xlFilterValues
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
You are very welcome. :)
 
Upvote 0
HI Mumps and everyone,
big problem, maybe i said this wrong but i want the filter to leave me everything but what in the list, your code hides everything but the list,
how can i get this to do it the otherway round?
 
Upvote 0
With a formula rather than VBA :)
Excel Formula:
=FILTER(Input!J10:J45,NOT(ISNUMBER(MATCH(Input!J10:J45,Data!G6:G124,0))))

Doug
 
Upvote 0
Try:
VBA Code:
Sub FilterData()
    Application.ScreenUpdating = False
    Dim v As Variant, v2 As Variant, i As Long, arr() As Variant, x As Long
    v = Sheets("Input").Range("J10:J500").Value
    v2 = Sheets("Data").Range("G6:G26").Value
    For i = LBound(v) To UBound(v)
        If IsError(Application.Match(v(i, 1), v2, 0)) Then
            x = x + 1
            ReDim Preserve arr(1 To x)
            arr(x) = v(i, 1)
        End If
    Next i
    Sheets("Input").Range("J9").AutoFilter Field:=1, Criteria1:=arr, Operator:=xlFilterValues
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,147
Messages
6,123,297
Members
449,095
Latest member
Chestertim

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