+ Reply to Thread
Results 1 to 9 of 9

Compare columns and return matching text VBA

  1. #1
    Registered User
    Join Date
    02-16-2017
    Location
    New York, NY
    MS-Off Ver
    MS Office 2010
    Posts
    4

    Compare columns and return matching text VBA

    Hello,

    I'm working on comparing a large string of text against another string of text and outputting any matching values in another column. I've only been able to compare the two and return whether it's a match or not or even highlight the differences (not exactly accurate). Another idiosyncrasy is that each cell contains a listing of individual names which are concatenated and separated by a delimiter (semicolon in this case), I'd like to avoid parsing these out individually, as my end goal is to have any matching names in that format separated by a semicolon.


    Column 1: Jack Johnson;Tom Jackson;Josh Hazard;Tom Petty;John Kowalski
    Column 2: Tom Petty;Charles Smith;John Terry;Steven Gerrard;Tom Jones;Nick Jones;Michael Schumacher;George Willis;Donald Simson;Jack Johnson
    Output Column:Tom Petty;Jack Johnson

    Another issue I've ran into is that there is overlap in some of the names (e.g., the Jack in Tom Jackson comes back as a match for the Jack in Jack Johnson). Is there any way to treat each name individually based on the delimiter?

    Any help or suggestions would be greatly appreciated.

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Compare columns and return matching text VBA

    Hi alekos,

    Give this a try:

    Please Login or Register  to view this content.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Compare columns and return matching text VBA

    oops... just realized it is not necessarily a list... could use Split function instead... a sample sheet would be ideal

  4. #4
    Registered User
    Join Date
    02-16-2017
    Location
    New York, NY
    MS-Off Ver
    MS Office 2010
    Posts
    4

    Re: Compare columns and return matching text VBA

    Please see attached.
    Attached Files Attached Files

  5. #5
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Compare columns and return matching text VBA

    How about:

    Please Login or Register  to view this content.

  6. #6
    Valued Forum Contributor
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,387

    Re: Compare columns and return matching text VBA

    try this WORK FOR ME
    Please Login or Register  to view this content.
    Last edited by daboho; 11-09-2018 at 01:48 PM.
    "Presh Star Who has help you *For Add Reputation!! And mark case as Solve"

  7. #7
    Registered User
    Join Date
    02-16-2017
    Location
    New York, NY
    MS-Off Ver
    MS Office 2010
    Posts
    4

    Re: Compare columns and return matching text VBA

    This is brilliant! I tried setting it up as a loop (my actual data set is exponentially larger), but I'm getting a subscript out of range error. I need this to run 68 times across the set of 2 columns & output in the 3rd column each time (columns are all next to each other). Is there any way to set it up to run a loop through those instead of defining each specific range?

    Set r = .Range("b2:D" & lr)
    Set r = .Range("e2:G" & lr)
    Set r = .Range("h2:J" & lr)
    .
    .
    .
    Set r = .Range("gu2:GW" & lr)

  8. #8
    Valued Forum Contributor
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,387
    Quote Originally Posted by alekos7 View Post
    This is brilliant! I tried setting it up as a loop (my actual data set is exponentially larger), but I'm getting a subscript out of range error. I need this to run 68 times across the set of 2 columns & output in the 3rd column each time (columns are all next to each other). Is there any way to set it up to run a loop through those instead of defining each specific range?

    Set r = .Range("b2:D" & lr)
    Set r = .Range("e2:G" & lr)
    Set r = .Range("h2:J" & lr)
    .
    .
    .
    Set r = .Range("gu2:GW" & lr)
    You just add range array
    Please Login or Register  to view this content.
    Or if your range is have sama space with other you can loop

    Please Login or Register  to view this content.

  9. #9
    Valued Forum Contributor
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,387

    Re: Compare columns and return matching text VBA

    And perhab you can change to this
    I am sorri not test
    Or another idea
    'b,e,h
    Please Login or Register  to view this content.
    In other code you can call
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to compare text of same row in two different columns and return matching words?
    By guest2013 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-17-2015, 03:22 PM
  2. Compare columns and finding matching values/text
    By debake in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-02-2014, 09:27 AM
  3. Replies: 0
    Last Post: 10-07-2013, 10:24 AM
  4. Replies: 2
    Last Post: 07-17-2013, 11:48 AM
  5. Replies: 1
    Last Post: 04-21-2013, 08:36 AM
  6. Replies: 6
    Last Post: 02-28-2013, 11:27 AM
  7. [SOLVED] Compare cells/columns and highlight matching text strings
    By luxbelle in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-25-2005, 06:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1