+ Reply to Thread
Results 1 to 13 of 13

Comparing Words in Cell and Showing Difference

  1. #1
    Forum Contributor
    Join Date
    02-10-2007
    MS-Off Ver
    Excel 2010
    Posts
    293

    Comparing Words in Cell and Showing Difference

    Hello,

    I am trying to compare a sequence of words between two cells and show the difference, separated by a comma.

    For Example:

    Cell A has: The quick brown dog jumped over the lazy dog
    Cell B has: The brown mouse jumped over the lazy cat and ran


    Desired Result: Column D: NEW WORDS in B not in A & Column E: Original Words in A Not in B


    The desired result is in Columns D & E. (Please see attached spreadsheet)

    Thanks for you're help.
    Attached Files Attached Files
    Last edited by VegasL; 01-25-2015 at 12:38 PM.

  2. #2
    Registered User
    Join Date
    01-20-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    1

    Re: Comparing Words in Cell and Showing Difference

    Didn't get what are you trying to do?

  3. #3
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Comparing Words in Cell and Showing Difference

    Can do this with a user defined function. For example

    Please Login or Register  to view this content.
    Open the VBA editor by hitting Alt F11.
    Insert a new module with Insert - Module
    Paste in the above function
    Go back to the sheet by hitting Alt F11.

    In a suitable cell, enter = NewWordsInB(A2,B2)

    Remember to save the workbook as a macro enabled workbook .xlsm
    Martin

  4. #4
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Comparing Words in Cell and Showing Difference

    Can do this with a user defined function. For example

    Please Login or Register  to view this content.
    Open the VBA editor by hitting Alt F11.
    Insert a new module with Insert - Module
    Paste in the above function
    Go back to the sheet by hitting Alt F11.

    In a suitable cell, enter = NewWordsInB(A2,B2)

    Remember to save the workbook as a macro enabled workbook .xlsm

  5. #5
    Forum Contributor
    Join Date
    02-10-2007
    MS-Off Ver
    Excel 2010
    Posts
    293

    Re: Comparing Words in Cell and Showing Difference

    Thanks mrice, that worked perfectly, appreciate the clear instructions as well. Do you know how to also do for column cell e2, Original Words in A Not in B ?

    Maybe put in one or seperate macro?

    I guess no way to do this in the traditional formula sense? not familiar with vba...

  6. #6
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Comparing Words in Cell and Showing Difference

    Here's the code for the other function

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    02-10-2007
    MS-Off Ver
    Excel 2010
    Posts
    293

    Re: Comparing Words in Cell and Showing Difference

    Thanks. In for new code use = OrginalWordsinA(A2,B2) ?

    Lastly, will this code work when i have more text in columns a and b for a defined range of cells?



    Appreciate your help!

  8. #8
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Comparing Words in Cell and Showing Difference

    Hi,

    enter

    =newwords(A1,B1) in a cell where A1 & B1 contain the two strings.

    One way
    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  9. #9
    Forum Contributor
    Join Date
    02-10-2007
    MS-Off Ver
    Excel 2010
    Posts
    293

    Re: Comparing Words in Cell and Showing Difference

    Hi Richard,

    You're pretty close:

    I updated code in cell E2 to read: =newwords(A2,B2) and that almost works. , i think in you're code it considers "test" and "tests" to be the same.

    I also added column b for matching words. for column f, i tried flipping around your original, to =newwords(B2,A2) but that didn't work.

    I put the desired results in updated attachment in column H..J, would you mind helping update?
    Attached Files Attached Files

  10. #10
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Comparing Words in Cell and Showing Difference

    Hi,

    Swapping them around seems to work for me and =newwords(b2,a2) is returning 'tests' & 'quiz'

    I agree the UDF is not distinguishing plurals like 'tests' from the singular 'test'. At the moment as long as the UDF finds a word string in one cell anywhere in the other string then it's not counting that as a different word.

    However does not Martin's UDF in post#6 give you exactly what you want - give or take the odd typo like 'orginal'

  11. #11
    Forum Contributor
    Join Date
    02-10-2007
    MS-Off Ver
    Excel 2010
    Posts
    293

    Re: Comparing Words in Cell and Showing Difference

    Richard,

    You're right. My bad. Now for column d, where I want to show the matching words, is there a way to do this in all one script?

    BTW..thanks to both of you. Really apprecaited.

  12. #12
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Comparing Words in Cell and Showing Difference

    A small modification to Martin's code will do it.

    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    02-10-2007
    MS-Off Ver
    Excel 2010
    Posts
    293

    Re: Comparing Words in Cell and Showing Difference

    Thanks Richard, OIC, so i add another module and then put in column D2 =samewords(A2,B2).

    Works great. Do you know how to modify the other scripts so it puts a comma "," after each word?


    Ok I got it, put a &"," like stNew = stNew & " " & st_1(x)&","
    Last edited by VegasL; 01-27-2015 at 01:27 AM.

+ 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. Comparing two Cell containing Number and giving the difference in third cell
    By aabhi2251 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-22-2014, 10:34 AM
  2. Difference from not showing up when filtered
    By mga8402 in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 08-07-2013, 06:51 PM
  3. Showing difference as a percentage
    By oliver79 in forum Excel General
    Replies: 1
    Last Post: 07-06-2010, 06:29 AM
  4. Showing a difference between values
    By MattG in forum Excel General
    Replies: 9
    Last Post: 09-14-2009, 05:02 PM
  5. showing difference value with out going over ref cell
    By aprils280zx in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-04-2007, 07:33 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