+ Reply to Thread
Results 1 to 14 of 14

How to search a cell for specific word and display only that word in another?

  1. #1
    Registered User
    Join Date
    08-04-2011
    Location
    Trondheim, Norway
    MS-Off Ver
    Excel 2003
    Posts
    7

    How to search a cell for specific word and display only that word in another?

    Hi!

    I am trying to search a cell for a specific item number, in this case KAO-XXXXX where X are digits.

    What I want is to check if the cell contains such a number, and if yes, return that number to the adjacent cell.

    Something like =IF(K2 contains "KAO-XXXXX"; KAO-XXXXX; " ")

    Help?
    Last edited by Yngin; 08-04-2011 at 09:42 AM.

  2. #2
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: How to search a cell for specific word and display only that word in another?

    Hello,

    So, if K2 starts with "KAO-" and ends in a 4 digit number, then return the value of K2?

    If so, try

    =IF(AND(Len(K2)=8,LEFT(K2,4)="KAO-",ISNUMBER(RIGHT(K2,4)*1)),K2,"")

    If that does not do it for you, please post a workbook with some sample data and the expected results. Create the results manually and explain the logic.

    cheers,
    Last edited by teylyn; 08-04-2011 at 06:32 AM.

  3. #3
    Registered User
    Join Date
    08-04-2011
    Location
    Trondheim, Norway
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: How to search a cell for specific word and display only that word in another?

    Well, not exactly.

    The cell contains several lines and sentences of text, separated by blank lines.
    The numbers I am looking for are never at the start, and they are "KAO-" followed by 6 digits.

    Thanks for helping

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,419

    Re: How to search a cell for specific word and display only that word in another?

    If you are checking for specific values as in the example:

    =IF(LEN(A1)-LEN(SUBSTITUTE(A1,"KAO-XXXXX",""))>0,"KAO-XXXXX","")

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: How to search a cell for specific word and display only that word in another?

    Can you post a sample workbook with some manually mocked up expected results?

    You say there are 6 digits after KAO, but your narrative shows only 5 X's.

    Please post some of your real data to work with to take the guesswork out of the equation.

  6. #6
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: How to search a cell for specific word and display only that word in another?

    @TM, as far as I read the question, the XXXXX are meant to be wildcards, not verbatim strings.

  7. #7
    Registered User
    Join Date
    08-04-2011
    Location
    Trondheim, Norway
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: How to search a cell for specific word and display only that word in another?

    Ok, that works for a specific number, great work :D

    But how about when the digits behind "KAO-" are unknown? The only certain fact is that there are six digits.

    Thanks

  8. #8
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: How to search a cell for specific word and display only that word in another?

    You can use the Search() function with wildcards, like this for a string that starts with "KAO-" and has 6 characters after that.

    =IF(SEARCH("KAO-??????",K2),MID(K2,SEARCH("KAO-",K2),10),"")

  9. #9
    Registered User
    Join Date
    08-04-2011
    Location
    Trondheim, Norway
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: How to search a cell for specific word and display only that word in another?

    Quote Originally Posted by teylyn View Post
    =IF(SEARCH("KAO-??????",K2),MID(K2,SEARCH("KAO-",K2),10),"")
    Okay, that kind of worked, only it returned the 10 letters that started 10 digits behind the KAO-number I was after :P

    Any idea how that happened?


    EDIT: Oh, my bad, I had some cell references mixed up. It works now! Thanks a lot, you guys saved me from going through tons of lines manually

  10. #10
    Registered User
    Join Date
    08-04-2011
    Location
    Trondheim, Norway
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: How to search a cell for specific word and display only that word in another?

    Okay, now I just need the lines without KAO-numbers to not return #VALUE!...

    That can be solved by a simple IF-sentence, right?

  11. #11
    Registered User
    Join Date
    08-04-2011
    Location
    Trondheim, Norway
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: How to search a cell for specific word and display only that word in another?

    Also, can one make it so that the KAO-number will be displayed only when it is on the form "KAO-XXXXXX" where X is a digit, so that where the cells contains, say, the text "there are different KAO-numbers linked to this", then it won't return "KAO-number"?

    If you know what I mean?
    Last edited by Yngin; 08-04-2011 at 07:27 AM.

  12. #12
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: How to search a cell for specific word and display only that word in another?

    I know what you mean.

    stand by

  13. #13
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: How to search a cell for specific word and display only that word in another?

    try

    Please Login or Register  to view this content.
    copy down

  14. #14
    Registered User
    Join Date
    08-04-2011
    Location
    Trondheim, Norway
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: How to search a cell for specific word and display only that word in another?

    Quote Originally Posted by teylyn View Post
    try

    Please Login or Register  to view this content.
    copy down
    Sweet, that works perfectly, many thanks

+ 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