matratus34
Board Regular
- Joined
- Nov 21, 2013
- Messages
- 74
Hi all,
I get data sets that I need to clean up by removing lines in the data that contain certain words.
I've manged to get some code to work that looks for a word in column D by filtering on that column and then deleting out those lines.
In my code the search word is set.
What I want to do is have a list of search words in column A on "Sheet2" and have the code loop through the list without me manually changing the word.
I've tried various loops but as usual keep failing!
Any help is greatly appreciated as always.
My current code is below.
Sub Test_Filter()
Dim ws As Worksheet
Dim DataRow As Long
Dim strSearch As String
'Select Active Worksheet
Set ws = ThisWorkbook.Worksheets("Data")
'Search for Word
strSearch = "Dog"
With ws
'~~> Remove any filters
.AutoFilterMode = False
DataRow = .Range("D" & .Rows.Count).End(xlUp).Row
With .Range("D1:D" & DataRow)
.AutoFilter Field:=1, Criteria1:="=*" & strSearch & "*"
.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With
'~~> Remove any filters
.AutoFilterMode = False
End With
End Sub
I get data sets that I need to clean up by removing lines in the data that contain certain words.
I've manged to get some code to work that looks for a word in column D by filtering on that column and then deleting out those lines.
In my code the search word is set.
What I want to do is have a list of search words in column A on "Sheet2" and have the code loop through the list without me manually changing the word.
I've tried various loops but as usual keep failing!
Any help is greatly appreciated as always.
My current code is below.
Sub Test_Filter()
Dim ws As Worksheet
Dim DataRow As Long
Dim strSearch As String
'Select Active Worksheet
Set ws = ThisWorkbook.Worksheets("Data")
'Search for Word
strSearch = "Dog"
With ws
'~~> Remove any filters
.AutoFilterMode = False
DataRow = .Range("D" & .Rows.Count).End(xlUp).Row
With .Range("D1:D" & DataRow)
.AutoFilter Field:=1, Criteria1:="=*" & strSearch & "*"
.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With
'~~> Remove any filters
.AutoFilterMode = False
End With
End Sub