+ Reply to Thread
Results 1 to 16 of 16

check whether all the words in a cell appear in another cell even if ordered differently

  1. #1
    Registered User
    Join Date
    07-17-2013
    Location
    miami, fl
    MS-Off Ver
    Excel 2016
    Posts
    28

    check whether all the words in a cell appear in another cell even if ordered differently

    Hello,

    I'd like a formula that returns true if ALL words within a cell (See A1 below) appear on another cell (B1), regardless of word order. Thanks in advance.

    Cell A1: House Tree Cat

    Cell B1: Bench Cat Pier Tree Door House

    Update: see attachment below
    Data_Workbook.xlsx
    Last edited by daatr; 04-21-2023 at 12:14 PM.

  2. #2
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: check whether all the words in a cell appear in another cell even if ordered different

    Try these in A2:A3


    A
    B
    1
    House Tree Cat
    Bench Cat Pier Tree Door House
    2
    3
    In A2: =LEN(A1)-LEN(SUBSTITUTE(A1," ",""))+1
    3
    TRUE
    In A3: =COUNT(SEARCH(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",LEN(A1))),(ROW(INDIRECT("1:"&A2))-1)*LEN(A1)+1,LEN(A1))),B1))=A2
    Last edited by FlameRetired; 04-19-2023 at 04:49 PM.
    Dave

  3. #3
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: check whether all the words in a cell appear in another cell even if ordered different

    And BTW: are you still using Excel 2003? If not please update your profile.

    If you are not familiar with how to update your profile find the dark blue menu at the top of this page that says
    Forum Actions
    . Click that and 'Edit Profile'.

  4. #4
    Registered User
    Join Date
    07-17-2013
    Location
    miami, fl
    MS-Off Ver
    Excel 2016
    Posts
    28

    Re: check whether all the words in a cell appear in another cell even if ordered different

    Hi Dave,

    Thanks for your response. Using your information, i'm getting a false response on A3. Please see attached. Attachment 826338

  5. #5
    Forum Expert azumi's Avatar
    Join Date
    12-10-2012
    Location
    YK, Indonesia
    MS-Off Ver
    Excel 2019
    Posts
    2,367

    Re: check whether all the words in a cell appear in another cell even if ordered different

    Quote Originally Posted by daatr View Post
    Hi Dave,

    Thanks for your response. Using your information, i'm getting a false response on A3. Please see attached. Attachment 826338
    It says Invalid Attachment specified cannot download it

  6. #6
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: check whether all the words in a cell appear in another cell even if ordered different

    Quote Originally Posted by daatr View Post
    Hi Dave,

    Thanks for your response. Using your information, i'm getting a false response on A3. Please see attached. Attachment 826338
    OK. I'll attach a workbook with the formulas.

    And in Excel 2007 you may need to array enter that formula.

    If you aren’t familiar with array-entered formulas array enter means the formula must be committed from edit mode by simultaneously pressing and holding down Ctrl and Shift while hitting Enter.

  7. #7
    Registered User
    Join Date
    07-17-2013
    Location
    miami, fl
    MS-Off Ver
    Excel 2016
    Posts
    28

    Re: check whether all the words in a cell appear in another cell even if ordered different

    Thank you very much for your help. The array enter fixed it, my apologies for not being aware of it.

    1. This is nearly what I wanted, the only thing that's left is that the formula is still getting false matches with partial words, so for example, if I put: "Do House Tree Cat" as the value for A1, I still get a true match because Do is a partial match of Door. Is there a way to correct it so it only returns true if all words are an exact match?

    2. I realize I'd appreciate your assistance on one extra variation on the first formula which can go in Cell A4. This formula is the same as 1 (recognizes exact word matches), with the addition of recognizing plural words.

    so for example, if B1: is Cats Pier Tree 54 68s

    a. if A1 is: Trees Cat -> formula would return true (plural and non-plural words match for both directions).
    b. If A1 is: 54s Tree OR 68 Tree – the formula will return false as numbers can’t be plural
    Last edited by daatr; 04-20-2023 at 11:46 AM.

  8. #8
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: check whether all the words in a cell appear in another cell even if ordered different

    Edited: Too much commentary. Needed to be reduced.

    WOW! That is a lot of conditions/exceptions. You mentioned none of this in the original post.

    I am not confident I can do it without several extra steps/lookup-tables/et al ... especially in earlier Excel products. Other contributors will hopefully prove me wrong. We'll see.

    Meanwhile I will see if I can summon community help on this one. Please stand by.
    Last edited by FlameRetired; 04-20-2023 at 01:31 PM.

  9. #9
    Registered User
    Join Date
    07-17-2013
    Location
    miami, fl
    MS-Off Ver
    Excel 2016
    Posts
    28

    Re: check whether all the words in a cell appear in another cell even if ordered different

    Sure, sounds good. Sorry for not being clearer in the original post. I appreciate your help.

  10. #10
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: check whether all the words in a cell appear in another cell even if ordered different

    Good deal.

    In the meantime please upload an Excel workbook with representative data and desired results ... hand typed. Sections Before and After.

  11. #11
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: check whether all the words in a cell appear in another cell even if ordered different

    By the way. Is the solution also to be Case Sensitive?

  12. #12
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: check whether all the words in a cell appear in another cell even if ordered different

    with an UDF,
    if you have 2 "Cats" in the first string and only 1 "Cat" in the 2nd, is that false or true
    for exemple "Cat cats dog mouse" and "cat dogs mouses" ???

    Please Login or Register  to view this content.
    EDIT : as FlameRetired asked, this solution is "for the moment" not case sensitive.
    Last edited by bsalv; 04-20-2023 at 03:18 PM.
    Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

  13. #13
    Registered User
    Join Date
    07-17-2013
    Location
    miami, fl
    MS-Off Ver
    Excel 2016
    Posts
    28

    Re: check whether all the words in a cell appear in another cell even if ordered different

    Thank you very much this is nearly the code i described. The one thing that's missing is that the plural/singular matching should go both ways, which i think you mentioned in a previous message. So in the file you attached, if A1 contained cat and B1 contained Cats- it should trigger a true response.

    I also noticed this file doesn't open on excel 2007. This is totally fine if you can't get it on this now ancient excel version, but in case there's an easy fix, feel free to let me know. Thanks.

  14. #14
    Registered User
    Join Date
    07-17-2013
    Location
    miami, fl
    MS-Off Ver
    Excel 2016
    Posts
    28

    Re: check whether all the words in a cell appear in another cell even if ordered different

    Sorry, I missed your message. Here's data that provides clear examples that would be rejected/approved by the code with reasons. This is not case sensitive.

    Workbook_Data.xlsx
    Last edited by daatr; 04-21-2023 at 12:47 PM.

  15. #15
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: check whether all the words in a cell appear in another cell even if ordered different

    i saved it as a ".xls", so that should work on your 2007, i hope.
    Attached Files Attached Files
    Last edited by bsalv; 04-22-2023 at 11:02 AM.

  16. #16
    Registered User
    Join Date
    07-17-2013
    Location
    miami, fl
    MS-Off Ver
    Excel 2016
    Posts
    28

    Re: check whether all the words in a cell appear in another cell even if ordered different

    It’s exactly what I wanted, thank you very much for your help. I gave you reputation boosts for both replies.

    I have one final request- I thought I’d be able to do that myself and save you the trouble but I was unable to, my apologies.

    The criteria the code uses are perfect, is it possible to just produce a different output depending on the case?

    So for example:
    If B1 is: Cats Pier Tree 54 68s
    -If A1 is Pier Tree -> output instead of True can be> Perfect Match (words match in exact order)
    -If A1 is Piers Tree -> output instead of True can be> Perfect Plural (words in order, but there’s a singular/plural mismatch)
    -If A1 is Cat Pier -> output instead of True can be> Perfect plural (plural reverse of the previous case)
    -If A1 is Cats Tree-> output instead of True can be> Mixed Match (words match out of order)
    -If A1 is Tree Piers -> output instead of True can be> Mixed Plural (words match out of order and there’s a singular/plural mismatch)
    -If A1 is Pier Cat -> output instead of True can be> Mixed Plural (plural reverse of the previous case)
    -False criteria/output stay the same

+ 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. [SOLVED] How to check if two cell contents have common words?
    By zastemutro in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-18-2022, 02:13 PM
  2. Replies: 2
    Last Post: 03-15-2018, 02:09 AM
  3. [SOLVED] Check if cell value starts with specific words
    By goranimo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-11-2016, 04:10 AM
  4. Check cell range for closest match of cell value (multiple words)
    By marcus76 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-22-2015, 11:23 AM
  5. [SOLVED] Check a Single Cell to See if Any Words from an Array are Present
    By sweetrevelation in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-01-2013, 08:48 PM
  6. Macro to check for duplicate words in a cell
    By pharri11 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-07-2007, 05:22 AM
  7. Check one Cell for multiple words in one macro line?
    By Hutas in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-08-2005, 10:34 PM

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