blacklist of words - find if cells have the value

in sheet 2, i have a list of 200 words

i sheet 1 i have 70k rows , col A has sentences

i need vba code that looks at the 200 words and deletse and row that contains a word from sheet2

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


pls try
Sub macro()
Set sh1 = Sheets("Sheet1")
Set sh2 = Sheets("Sheet2")
Set regex = CreateObject("VBScript.RegExp")

Set rngWrds = Range(sh2.Range("A1"), sh2.Range("A" & Rows.Count).End(xlUp))
aRng = WorksheetFunction.Index(WorksheetFunction.Transpose(rngWrds), 1, 0)
strRng = Join(aRng, "|")
    With regex
        .Global = False
        .MultiLine = False
        .IgnoreCase = True
        .Pattern = "\b(" & strRng & ")+\b"
    End With
For Idx = sh1.Range("A" & Rows.Count).End(xlUp).Row To 1 Step -1
    If regex.Test(sh1.Range("A" & Idx)) Then
        sh1.Range("A" & Idx).EntireRow.Delete
    End If
End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
finnstoneAuthor Commented:
aRng - throws error
Could you send a dummy?
Price Your IT Services for Profit

Managed service contracts are great - when they're making you money. Yes, you’re getting paid monthly, but is it actually profitable? Learn to calculate your hourly overhead burden so you can master your IT services pricing strategy.

finnstoneAuthor Commented:
the list must have at least 2 words even if the same

How's the performance of the .Test() method?  If you want to play with performance, you might try sorting the entries by frequency.
Here's a routine that will return a dictionary of the 5000 most frequent English words.
Function WordFreq() As Object
    Dim dicWords As Object
    Dim oRE As Object
    Dim oMatches As Object
    Dim oM As Object
    Dim oXMLHTTP As Object
    Dim strHTML As String
    Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP")
    oXMLHTTP.Open "GET", "", False
    Do Until oXMLHTTP.ReadyState = 4
    If oXMLHTTP.Status = 200 Then
        strHTML = oXMLHTTP.responsetext
        Set dicWords = CreateObject("scripting.dictionary")
        Set oRE = CreateObject("vbscript.regexp")
        oRE.Global = True
        oRE.Pattern = "<tr>\s*<td>(\d+)</td>\s*<td>([^<]+)</td>"
        Set oMatches = oRE.Execute(strHTML)
        For Each oM In oMatches
            If dicWords.exists(oM.submatches(1)) Then
                dicWords(oM.submatches(1)) = oM.submatches(0)
            End If
    End If
    Set WordFreq = dicWords

End Function

Open in new window

finnstoneAuthor Commented:
new one if you can help, opposite this time with a whitelist need
need to put a 1 value in column AA where the value in A matches a word in sheet2
That isn't a valid link to an open question
finnstoneAuthor Commented:
finnstoneAuthor Commented:
BUT it exactly what i wrote above and below-

need to put a 1 value in column AA where the value in A matches a word in sheet2
finnstoneAuthor Commented:
rgonzo, why is this not working now? it seems to be the particular data set. can you look?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.