VBA: Filter that contains with multiple criteria

unknownymous

Board Regular
Joined
Sep 19, 2017
Messages
249
Office Version
  1. 2016
Platform
  1. Windows
Hi Gurus,

I have below sample raw data. I need to filter and move the information that contains certain words. Example I need to Copy the whole row that contains "Missed", "Chck", "Note"& "Check" (might add more) in the Subject Column.

AccountSubjectNumberxNote 1Note 2Note 3
001Math - Missed95
002Science90
003History (Chck)85
004Language Arts with Note80
005Foreign Language 75
006Others Check70


Example: Another tab will be created for below Output

AccountSubjectNumberxNote 1Note 2Note 3
001Math - Missed90
003History (Chck)85
004Language Arts with Note80
006Others Check70


Do you have any idea on how to code this or if this is feasible? Any help will be much appreciated. :)
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Check Norie's thread, change the search names and it will do what you need it to do. You only then need to add to format the column width and row height


Adjust this part of the code

VBA Code:
strArray = Array("bank", "KLM", "firm")

To

VBA Code:
'What to check for within the cells
    strArray = Array("Chck", "Note", "Check", "Missed")

Add this extra code after the Next I to adjust the column width and row height

VBA Code:
With Cells
    .ColumnWidth = 58.29
    .RowHeight = 60.75
    .EntireRow.AutoFit
    .EntireColumn.AutoFit
    End With
 
Upvote 0
or try this
amend "Name of Sheet" = name of the sheet containing original data

VBA Code:
Sub CopyValues()
    Dim ws1 As Worksheet, ws2 As Worksheet, lr As Long, r As Long, lookFor As String
    Dim a As Long, arr As Variant, wf As WorksheetFunction
  
    Set wf = WorksheetFunction
    Set ws1 = Sheets("Name of Sheet")
    lr = ws1.Cells(Rows.Count, 1).End(xlUp).Row
'get words
    lookFor = "missed chck note"
    lookFor = wf.Trim(InputBox("words separated by space", "Search for what?", lookFor))

    If lookFor <> "" Then
        arr = Split(lookFor)
'create new sheet based on old sheet
        ws1.Copy before:=Sheets(1)
        Set ws2 = Sheets(1)
        ws2.UsedRange.Offset(1).Clear
'add required rows
        For r = 2 To lr
            For a = 0 To UBound(arr)
                If wf.CountIf(ws1.Cells(r, 2), "*" & arr(a) & "*") > 0 Then
                    ws1.Rows(r).Copy ws2.Cells(Rows.Count, 1).End(xlUp).Offset(1)
                    Exit For
                End If
            Next a
        Next r
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,300
Members
452,633
Latest member
DougMo

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