• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 55
  • Last Modified:

whitelist of words

opposite of this one.
https://www.experts-exchange.com/questions/29079746/blacklist-of-words-find-if-cells-have-the-value.html#a42444598

need to put a 1 value in column AA where the value in A matches a word in sheet2
0
finnstone
Asked:
finnstone
  • 4
  • 3
1 Solution
 
Martin LissOlder than dirtCommented:
Is "AA" the column where you want a "1"?

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("AA" & Idx) = "1"
    End If
Next
End Sub

Open in new window

0
 
Rgonzo1971Commented:
HI,

If you want the count of matched words instead of 1
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 = True
        .MultiLine = True
        .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
        set Mtchs = regex.Execute(sh1.Range("A" & Idx))
        sh1.Range("AA" & Idx) = Mtchs.Count
    End If
Next
End Sub

Open in new window

Regards
0
 
finnstoneAuthor Commented:
thx!
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
Martin LissOlder than dirtCommented:
You’re welcome and I’m glad I was able to help.

If you expand the “Full Biography” section of my profile you’ll find links to some articles I’ve written that may interest you.

Marty - Microsoft MVP 2009 to 2017
              Experts Exchange MVE 2015
              Experts Exchange Top Expert Visual Basic Classic 2012 to 201
0
 
finnstoneAuthor Commented:
THIS does not seem to be working as intended. please see attached. why are rows getting flagged as meting the white list conditions when they do not have any of the words matching the column in sheet2??!

thanks
whitelist-twitter.xlsm
0
 
Martin LissOlder than dirtCommented:
An example or two please?
0
 
finnstoneAuthor Commented:
look at rows 17,18,21 ...none have words that are in sheet2
0
 
Martin LissOlder than dirtCommented:
Row 17 contains 'technology'  which matches (except for case) Sheet2 row 81.
Row 18 contains 'platform'  which matches (except for case) Sheet2 row 65.
Row 21 contains 'Business'  which matches Sheet2 row 13.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now