+ Reply to Thread
Results 1 to 18 of 18

Return occurences of similar values from text string

  1. #1
    Registered User
    Join Date
    02-22-2012
    Location
    UK
    MS-Off Ver
    Excel 2010 and 2013
    Posts
    25

    Return occurences of similar values from text string

    I am trying to get all occurrences of text from within one cell, for example

    Dog0001 Cat001 Dog000007 Cat008 etc

    Ideally it should return any word that return anything that begins with 'Dog' i.e. Dog0001 Dog000007

    Thanks

  2. #2
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Return occurences of similar values from text string

    Assuming your text string is in A1 and B1 has DOG or Dog or dog, then try this.....

    Please Login or Register  to view this content.
    This will return 2.

    Does this work?
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  3. #3
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Return occurences of similar values from text string

    Sorry I completely missed your requirement, you are trying to return occurrences instead of counting the occurrences.

  4. #4
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2503
    Posts
    13,702

    Re: Return occurences of similar values from text string

    This will work but only for two instances.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    BTW can those instances be in separate cells?
    Last edited by FlameRetired; 05-20-2015 at 02:48 AM.

  5. #5
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,939

    Re: Return occurences of similar values from text string

    please attach a sample file with expected result
    Samba

    Say thanks to those who have helped you by clicking Add Reputation star.

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

    Re: Return occurences of similar values from text string

    I tried to do it all in one cell but couldn't. Assuming the text is in B1 and with a helper cell in A1 enter this and fill across as far as needed.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    There are empty cells between each returned item, but it finds all instances. File is attached.


    Edit This small adjustment concatenates.....eventually. (Not in the file.)
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by FlameRetired; 05-20-2015 at 04:02 AM.

  7. #7
    Registered User
    Join Date
    02-22-2012
    Location
    UK
    MS-Off Ver
    Excel 2010 and 2013
    Posts
    25

    Re: Return occurences of similar values from text string

    Have attached as requested with expected outcome. Ideally whole word that begins with 'Dog' to be extracted.

    Thanks for the replies so far..
    Attached Files Attached Files

  8. #8
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Return occurences of similar values from text string

    Hi.

    If you want the returns placed into a single-cell, comma- or space-separated, then this will require VBA (otherwise unfeasibly long formulas).

    Placing the returns each into individual cells, however, is no problem using worksheet formulas alone, if that is something you would consider.

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  9. #9
    Registered User
    Join Date
    02-22-2012
    Location
    UK
    MS-Off Ver
    Excel 2010 and 2013
    Posts
    25

    Re: Return occurences of similar values from text string

    Quote Originally Posted by FlameRetired View Post
    I tried to do it all in one cell but couldn't. Assuming the text is in B1 and with a helper cell in A1 enter this and fill across as far as needed.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    There are empty cells between each returned item, but it finds all instances. File is attached.


    Edit This small adjustment concatenates.....eventually. (Not in the file.)
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    This worked but only issue is that the return text are in different columns. Ideally would like all combined into single cell

  10. #10
    Registered User
    Join Date
    02-22-2012
    Location
    UK
    MS-Off Ver
    Excel 2010 and 2013
    Posts
    25

    Re: Return occurences of similar values from text string

    Quote Originally Posted by XOR LX View Post
    Hi.

    If you want the returns placed into a single-cell, comma- or space-separated, then this will require VBA (otherwise unfeasibly long formulas).

    Placing the returns each into individual cells, however, is no problem using worksheet formulas alone, if that is something you would consider.

    Regards


    I would not mind the returns into individual cells as long they are in columns next to each others excluding any blanks

  11. #11
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Return occurences of similar values from text string

    Based on your workbook, put e.g. "Dog" in B1 and then this formula in C1:

    =QUOTIENT(LEN(A2)-LEN(SUBSTITUTE(A2,B1,"")),LEN(B1))

    Then this array formula** in B2:

    =IF(COLUMNS($A:A)>$C$1,"",TRIM(LEFT(SUBSTITUTE(MID($A2,SMALL(IF(MID($A2,ROW(INDEX(A:A,1):INDEX(A:A,LEN($A2)-LEN($B$1)+1)),LEN($B$1))=$B$1,ROW(INDEX(A:A,1):INDEX(A:A,LEN($A2)-LEN($B$1)+1))),COLUMNS($A:A)),LEN($A2))," ",REPT(" ",LEN($A2))),LEN($A2))))

    Copy this formula to the right until you start to get blanks for the results.

    Regards


    **Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).

  12. #12
    Registered User
    Join Date
    02-22-2012
    Location
    UK
    MS-Off Ver
    Excel 2010 and 2013
    Posts
    25

    Re: Return occurences of similar values from text string

    This works the way I was hoping for - thanks



    Quote Originally Posted by XOR LX View Post
    Based on your workbook, put e.g. "Dog" in B1 and then this formula in C1:

    =QUOTIENT(LEN(A2)-LEN(SUBSTITUTE(A2,B1,"")),LEN(B1))

    Then this array formula** in B2:

    =IF(COLUMNS($A:A)>$C$1,"",TRIM(LEFT(SUBSTITUTE(MID($A2,SMALL(IF(MID($A2,ROW(INDEX(A:A,1):INDEX(A:A,LEN($A2)-LEN($B$1)+1)),LEN($B$1))=$B$1,ROW(INDEX(A:A,1):INDEX(A:A,LEN($A2)-LEN($B$1)+1))),COLUMNS($A:A)),LEN($A2))," ",REPT(" ",LEN($A2))),LEN($A2))))

    Copy this formula to the right until you start to get blanks for the results.

    Regards


    **Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).

  13. #13
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Return occurences of similar values from text string

    You're welcome!

  14. #14
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2503
    Posts
    13,702

    Re: Return occurences of similar values from text string

    @ XOR LX

    =IF(COLUMNS($A:A)>$C$1,"",TRIM(LEFT(SUBSTITUTE(MID($A2,SMALL(IF(MID($A2,ROW(INDEX(A:A,1):INDEX(A:A,LEN($A2)-LEN($B$1)+1)),LEN($B$1))=$B$1,ROW(INDEX(A:A,1):INDEX(A:A,LEN($A2)-LEN($B$1)+1))),COLUMNS($A:A)),LEN($A2))," ",REPT(" ",LEN($A2))),LEN($A2))))
    Very slick formula! I particularly like the ROW(INDEX(A:A,1):INDEX(A:A,LEN($A2)-LEN($B$1)+1)) part. I've never seen this construction before.

    Thank you for showing us yet one more opportunity to kick INDIRECT to the curb! LOL

    FR

  15. #15
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,939

    Re: Return occurences of similar values from text string

    can use ROW(a$1:INDEX(A:A,LEN($A2)-LEN($B$1)+1)) instead of Row(INDEX(A:A,1):INDEX(A:A,LEN($A2)-LEN($B$1)+1))

  16. #16
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Return occurences of similar values from text string

    Quote Originally Posted by FlameRetired View Post
    Thank you for showing us yet one more opportunity to kick INDIRECT to the curb! LOL
    Indeed!

    INDEX is used nowhere nearly enough as it should be, in my opinion. And yet constructions using INDIRECT, OFFSET, and even ADDRESS (ouch!) abound, even when these can almost always be replaced with a simple, non-volatile (well, almost) INDEX set-up.

    Cheers!

  17. #17
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Return occurences of similar values from text string

    Quote Originally Posted by nflsales View Post
    can use ROW(a$1:INDEX(A:A,LEN($A2)-LEN($B$1)+1)) instead of Row(INDEX(A:A,1):INDEX(A:A,LEN($A2)-LEN($B$1)+1))
    You can, but the second is more robust.

    For example, if row 1 is for whatever reason deleted, then your version will return a #REF! error, whereas mine will continue to function correctly.

    Of course, both versions will result in that error if column A is deleted, and this is why it makes sense to make the choice of column reference (i.e. A:A) in this construction to be one which holds the data, and so is not likely to be deleted.

    Regards

  18. #18
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2503
    Posts
    13,702

    Re: Return occurences of similar values from text string

    Quote Originally Posted by nflsales View Post
    can use ROW(a$1:INDEX(A:A,LEN($A2)-LEN($B$1)+1)) instead of Row(INDEX(A:A,1):INDEX(A:A,LEN($A2)-LEN($B$1)+1))
    Thanks for that one, too.

+ 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] Nested IF statements to FIND text string and return set values.
    By stuartm4h in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-12-2013, 12:03 PM
  2. [SOLVED] INDEX, cells containing text within string, return corresponding values in next column
    By amazingg64 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-05-2012, 08:30 AM
  3. Search for occurences of text string from a list
    By howardphillis in forum Excel General
    Replies: 13
    Last Post: 05-25-2012, 08:37 AM
  4. Replies: 9
    Last Post: 10-17-2011, 04:33 PM
  5. Search text string for range of text values - return match
    By crugg in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-03-2010, 09:55 AM

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