+ Reply to Thread
Results 1 to 21 of 21

Matching a small # string against a larger # string

  1. #1
    Registered User
    Join Date
    03-31-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    13

    Matching a small # string against a larger # string

    After a considerable amount of searching, I cannot find an exact answer to my quest, and am confused at this point if I should be trying to use match, vlookup, both, or a completely different function.

    It seems like a simple task. I have a 7 digit string of numbers, from 1 to 50. They are random, but in consecutive order, i.e 3,15,22,26,33,41,48. I then have a listing of larger strings of 25 numbers that are organized the same way, 1-50, random and in order. I want to find the first time that the 7 digit string occurs in one of the 25 digit strings.

    I used the wildcard * with the Match function, but would only get an affirmative hit if the order of the 7 digit string happened to match exactly the same way inside of a 25 digit string. I.E., 21,22,26,27,31,32,40 would match if inside the large string was 15,21,22,26,27,31,32,40,43 but not if inside the large string was 15,21,22,26,27,30,31,32,40,43.

    Any help would be appreciated.

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,938

    Re: Matching a small # string against a larger # string

    I just tried to =match() based on what you want to find, with the 2 large strings, and it gave me a result of 2. With short string in A1, and your 2 long strings in C1:C2, try something like...

    =IF(MATCH($A$1,$C$1:$C1)=1,"1st Found","")

    Copy down...let me know if this is what you want?
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Matching a small # string against a larger # string

    If 21,22,26,27,31,32,40 is in A2 and 15,21,22,26,27,30,31,32,40,43 is in M2

    then
    =AND(ISNUMBER(FIND(TRIM(MID((SUBSTITUTE(SUBSTITUTE(","&$A2,",",REPT(" ",255),{1,2,3,4,5,6,7}),",",REPT(" ",255),{1,2,3,4,5,6,7})),255,255))&",",M2))) will return TRUE.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  4. #4
    Registered User
    Join Date
    03-31-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Matching a small # string against a larger # string

    Quote Originally Posted by mikerickson View Post
    If 21,22,26,27,31,32,40 is in A2 and 15,21,22,26,27,30,31,32,40,43 is in M2

    then
    =AND(ISNUMBER(FIND(TRIM(MID((SUBSTITUTE(SUBSTITUTE(","&$A2,",",REPT(" ",255),{1,2,3,4,5,6,7}),",",REPT(" ",255),{1,2,3,4,5,6,7})),255,255))&",",M2))) will return TRUE.
    What change would be made to that to find the first occurrence of the 7 string in column M with multiple strings?? Would M2:M102 at the end work?

  5. #5
    Registered User
    Join Date
    03-31-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Matching a small # string against a larger # string

    Quote Originally Posted by FDibbins View Post
    I just tried to =match() based on what you want to find, with the 2 large strings, and it gave me a result of 2. With short string in A1, and your 2 long strings in C1:C2, try something like...

    =IF(MATCH($A$1,$C$1:$C1)=1,"1st Found","")

    Copy down...let me know if this is what you want?
    It worked, if I used $C1:$C1 instead of $C$1:$C1, when I copied down. But then it would still show a positive hit when I went back and changed the small string so that it shouldn't match. Not sure what is going on, but I will look at it more.

  6. #6
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Matching a small # string against a larger # string

    You'd have a much easier time if you split all the numbers into their own cells, rather than working with delmited strings.

  7. #7
    Registered User
    Join Date
    03-31-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Matching a small # string against a larger # string

    Quote Originally Posted by mikerickson View Post
    You'd have a much easier time if you split all the numbers into their own cells, rather than working with delmited strings.
    I can do it either way. I wasn't having any luck either with them in their own cells, I would actually prefer it that way. Any suggestions?

    Btw, I never could get your other formula to return "True". I copied/pasted it, and entered it in manually and still got "False" when comparing just the 2 strings.

  8. #8
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Matching a small # string against a larger # string

    Did you try entering it with Ctrl-Shift-Enter?

  9. #9
    Registered User
    Join Date
    03-31-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Matching a small # string against a larger # string

    Quote Originally Posted by mikerickson View Post
    Did you try entering it with Ctrl-Shift-Enter?
    Yea, not making a difference. Must be doing it wrong.

  10. #10
    Registered User
    Join Date
    03-31-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Matching a small # string against a larger # string

    Tried a few more times with the Ctrl-Shift-Enter. It's getting entered correctly as an array, but still showing false on just the 1 test. What was the idea on having the "strings" in multiple cells as opposed to one?

  11. #11
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Matching a small # string against a larger # string

    Select the cell an use Text to Columns with a comma delimiter.

  12. #12
    Registered User
    Join Date
    03-31-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Matching a small # string against a larger # string

    Quote Originally Posted by mikerickson View Post
    Select the cell an use Text to Columns with a comma delimiter.
    I understand that part. I was curious on your earlier post that I would have an easier time having it set up this way. What is the easier way solution? I have made recent progress with an extensive IF/AND/OR formula. But not sure that is the easiest way. I appreciate the suggestions by the way, I am narrowing it down.

  13. #13
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Matching a small # string against a larger # string

    If you have comma delimited strings in A2:A11 and a test (comma delimited) string in D2, the CSE formula
    =MATCH("*,"&SUBSTITUTE(C3&",",",",",*"),","&$A$1:$A$100&",",0)

    will return the first row whose string has all of the elements of the test string.
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    03-31-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Matching a small # string against a larger # string

    Thanks for the input, I will play with this today. It looks VERY promising. I had hit a dead-end with the IF/AND/OR route.

    I did get myself mixing apples and oranges on the discussion about "the easier way", and the "text to column with a comma delimiter".

    Is there a simple change to your formula to get it to work with the "numbers split in their own cells", the easier way you first mentioned, as opposed to the comma delimited cell?
    Last edited by Newbie1973; 04-01-2012 at 07:53 AM.

  15. #15
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Matching a small # string against a larger # string

    In the attached, =IF(SUMPRODUCT(COUNTIF(S2:AG2,$I$2:$O$2))=7,"match", "no match") will tell you whether the test array in I2:O2 matches on of the arrays in S2:AG11.

    You should read this about cross-posting.
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    03-31-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Matching a small # string against a larger # string

    Thanks for the additional suggestion, looks like a winner. I will make sure both forums are updated and shown as "solved" if it works as good as it appears it will. Thanks again for the input.

  17. #17
    Registered User
    Join Date
    03-31-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Matching a small # string against a larger # string

    Crap. I looked at it to quickly. I have multiple 7 string and multiple 25 strings to test. I don't see a way to have that multiple testing. Your earlier solution with the commas is exactly what I'm looking for, but now with multiple cell strings instead of single cell strings.

  18. #18
    Registered User
    Join Date
    03-31-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Matching a small # string against a larger # string

    I do see where cross-posting gets confusing. To update, I have a solution for single celled strings with spaces and commas. I can move forward with either and appreciate the input. I would still like to test a solution with the strings in multiple cells if someone has one.

    The single cell with spaces solution is here:
    http://www.mrexcel.com/forum/showthread.php?t=625583

  19. #19
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Matching a small # string against a larger # string

    As is a mult-cell solution.

  20. #20
    Registered User
    Join Date
    03-31-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Matching a small # string against a larger # string

    I could not get the macro/vba section of my Developer tab to work, and have officially given up. I did take your comma solution and modified it for spaces, since it looks "cleaner" on the worksheet, and it's working great. Assuming that any "multiple cell" solutions would require a macro, I am calling this one solved. Thanks for the input.

  21. #21
    Registered User
    Join Date
    03-31-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Matching a small # string against a larger # string

    For anyone interested a solution was posted for the "multiple cell" string issue on the other forum, here:

    http://www.mrexcel.com/forum/showthr...=625583&page=2

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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