compare words in text with a list of comma separated terms

davidmyers

Board Regular
Joined
Jan 29, 2017
Messages
88
Office Version
  1. 2016
Platform
  1. Windows
Hi I'm looking for a vba solution for the following:
Sheet1 Col A: Group Name
Col B: list of comma separated terms (for this Group)


Sheet2 Col A: text string
Col B: Group Name


I need to loop thru all the Groups in Sheet 1 and check if any of the terms in Sheet1 ColB appear in the text in Sheet2 Col A, if a match is found then copy the Group Name (Sheet1 ColA) to Sheet2 ColB and continue with the next cell in Sheet2 Col A.
What I have so far is:

Code:
For each cell in Sheet2ColA
     For each Group in Sheet1ColA
        If  (word in Sheet2ColA  is found in Sheet1ColB) Then
             Copy Sheet1ColA (Group Name) to Sheet2ColB
             Exit For
        End If
    Next Group
Next  cell in Sheet2ColA

Need help to write the VBA
Thanks
David
 
Last edited:

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Thanks for the file.
I had totally misunderstood your needs, but try Rick's code, as that seems to do what you're after.
 
Upvote 0
Thanks for your time, sorry I didn't load the file from the beginning, I will in future.
Yes Ricks solution worked perfectly
 
Upvote 0
Hi Rick,
[FONT=Helvetica, Arial, Verdana, sans-serif]I need to compare whole words - not substrings - in text in cell Sheet1 Col A with a list of terms in Sheet2 Col C - 1 term / row - when a match is found copy same row Sheet2 Col D to Sheet1 Col E and continue with next cell Sheet1 Col A.[/FONT]

[FONT=Helvetica, Arial, Verdana, sans-serif]The code you gave me above worked perfectly, but now instead of a comma separated list and a group name, I have the keywords in Sheet2 Col C and the Group name in the same row Col D - and I'm really struggling trying to use your code
[/FONT]Really appreciate any help.

David
 
Upvote 0
@davidmyers

Cross-Posting

While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Last edited:
Upvote 0
There is no connection between the 2 forum, but a lot of members here also post to other sites. Therefore there is a good chance that you will be found out.
All we ask, is that you post links to ALL other sites where you have posted this question. And that you also do that for any future questions.
 
Upvote 0

Forum statistics

Threads
1,223,900
Messages
6,175,276
Members
452,629
Latest member
SahilPolekar

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