+ Reply to Thread
Results 1 to 10 of 10

Thread: if cell contains a specific text, then put that specific text into a different cell

  1. #1
    Registered User
    Join Date
    01-26-2012
    Location
    Paul Green
    MS-Off Ver
    Microsoft Excel 2008 for Mac
    Posts
    8

    if cell contains a specific text, then put that specific text into a different cell

    I am trying to create a formulae that searches a cell for a specific text (word), and then if it finds that text, that same text is put into a different cell.

    Then I am wanting this formulae to search for a number of different texts (words) in a single cell, and for every one of those text (words) that are found, that same text (word) is put into the one/same different cell.

    For example,

    cell A3 (contains the following words)
    risk
    box
    cat
    mouse
    hat

    Formulae to search cell A3, for "risk" and "cat" and "hat"

    cell B5 (formulae puts words into cell B5, separated by commas and spaces)
    risk, cat, hat

    Any ideas would be appreciated
    Attached Files Attached Files
    Last edited by rustyoldtruck; 01-26-2012 at 05:15 PM.

  2. #2
    Registered User
    Join Date
    01-26-2012
    Location
    Paul Green
    MS-Off Ver
    Microsoft Excel 2008 for Mac
    Posts
    8

    Re: if cell contains a specific text, then put that specific text into a different ce

    Bump no response

  3. #3
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,228

    Re: if cell contains a specific text, then put that specific text into a different ce

    This won't be pretty if you dumbed that question down too far, but this is usable so far...

    B5: =SUBSTITUTE(TRIM(IF(ISNUMBER(SEARCH("risk", A3)), " risk", "") & IF(ISNUMBER(SEARCH("cat", A3)), " cat", "") & IF(ISNUMBER(SEARCH("hat", A3)), " hat", "")), " ", ", ")
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  4. #4
    Registered User
    Join Date
    01-26-2012
    Location
    Paul Green
    MS-Off Ver
    Microsoft Excel 2008 for Mac
    Posts
    8

    Re: if cell contains a specific text, then put that specific text into a different ce

    Awesome. Thanks very much. It works !!!!!!!! The things that I don't know?? I was trying with similar formulae but did not use the &, SUBSTITUTE< TRIM - very good!!

    I used word strings - e.g. instead of "risk", I used "risk management". What happened was that it found and placed the word "risk management" in cell B5, but it separated the words with a comma - i.e. "risk, management" ?? I am actually wanting it to return "risk management" If you know how to correct, it would be greatly appreciated

    If I could trouble you/others a little further. I would love to know how to do the following - same situations but looking for a way to automate a little more.

    That is,

    cell A3 (contains the following words)
    risk
    box
    cat
    mouse
    hat

    Formulae to search cell A3, for "risk" and "cat" and "hat" and about 40 more words

    cell B5 (formulae puts words into cell B5, separated by commas and spaces)
    risk, cat, hat

    So, one way of doing this is to just keep repeating the "&IF(ISNUMBER ...." for all the different words. This would make the formulae very long and also if I made a change to a word, I would have to redo the formulae

    So, wondering if there is a way of having the 40 or more words to be in one cell, from which the formulae would pic the words risk, cat, hat and the other 40 words, and search cell B5 to produce - "risk, cat, hat" or any of the other 40 or so words that matched.
    This method would also mean that a change(addition, deleting) in a word could be managed by adding that word to the 'one cell' rather than re-doing the formulae.

    Any more thoughts much appreciated?
    Attached Files Attached Files
    Last edited by rustyoldtruck; 01-26-2012 at 10:59 PM.

  5. #5
    Valued Forum Contributor
    Join Date
    07-20-2011
    Location
    mysore
    MS-Off Ver
    Excel 2003
    Posts
    423

    Re: if cell contains a specific text, then put that specific text into a different ce

    Pl see the attached file. Helper cells are used to get flexibility you want to have.
    Feel free to to give your opinion or clarification.
    With regards
    Attached Files Attached Files

  6. #6
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,228

    Re: if cell contains a specific text, then put that specific text into a different ce

    The original question is fixed to multiple word with another trick like this:

    =SUBSTITUTE(SUBSTITUTE(TRIM(IF(ISNUMBER(SEARCH("risk management", A3)), " risk|management", "") & IF(ISNUMBER(SEARCH("cat", A3)), " cat", "") & IF(ISNUMBER(SEARCH("hat", A3)), " hat", "")), " ", ", "), "|", " ")


    I still think the examples with words like "cat" and "hat" are misguided. Surely "risk management", "return on investment", "capitalization".... strings that match your actual strings are worth putting into the original question? When you need 40, the suggestion above is simply unwieldy.

    What you're doing is called STRING CONCATENATION and it is not really a builtin Excel function. But there are many ready-to-use VBA solutions for adding this capability into your workbook. You would have to save your workbook as .xlsm, but the end result would be much more friendly to use.

    Are you interested in a VBA solution? I'm assuming in the end you will be searching MULTIPLE cells looking for the 40+ words? If so, no more make believe examples. Please do the following.

    1) Create a workbook with the list of the actual 40 words (or phrases) in a single column
    2) Include the actual layout of your real workbook showing the multiple examples of real strings you would want to search
    3) If there will be more than one long string to search, show how that actually looks in your real workbook and where you'd want the answers to appear for each searched string.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  7. #7
    Registered User
    Join Date
    01-26-2012
    Location
    Paul Green
    MS-Off Ver
    Microsoft Excel 2008 for Mac
    Posts
    8

    Re: if cell contains a specific text, then put that specific text into a different ce

    Thanks for your suggestion and assertiveness.

    In relation to the attached workbook,

    I am wanting the formulae to do the following:

    1. Search Data EntryI4 for any words that are contained in 'Roles' worksheet; If match is made, then for each matched word, the word is to be put into Data EntryC4
    2. Search Data EntryI4 for any words that are contained in 'Categories' worksheet; If match is made, then for each matched word, the word is to be put into Data EntryD4
    3. Do not want it to be case sensitive; Do not want the same word repeated more than once in the one cell

    Then this sequence is to be repeated for Data EntryI4 to I319 and Data EntryC4 to C319 and Data EntryD4 to D319
    Attached Files Attached Files
    Last edited by rustyoldtruck; 01-27-2012 at 05:42 PM.

  8. #8
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,228

    Re: if cell contains a specific text, then put that specific text into a different ce

    Well, I wrote you a new FUNCTION that works a lot like SUMIF(), you can actually put this formula into C10 and it would work:

    =SEARCHSTRINGS($I10, Roles!$A:$A, ",", TRUE)

    ....that would give you all the Roles that matched. But this new function is very calc intense... when I copied it to the entire column C the sheet screeched to a halt. I thought it was better to let a macro use the function to enter the value for you in the column C cells as flat values. So I added some macros and buttons to call them. You have to click the buttons to update the columns, they won't update themselves.

    Option Explicit
    
    Sub AddRoles()
    Dim ROLErng As Range, r As Range
    
        Set ROLErng = Range("I:I").SpecialCells(xlConstants)
        
        For Each r In ROLErng
            r.Offset(, -6).Value = SEARCHSTRINGS(r, Sheets("Roles").Range("A:A").SpecialCells(xlConstants), ",", True)
        Next r
    
        Range("C3") = "3. Select Role"
    End Sub
    
    Sub AddCategories()
    Dim CATEGrng As Range, c As Range
    
        Set CATEGrng = Range("I:I").SpecialCells(xlConstants)
        
        For Each c In CATEGrng
            c.Offset(, -5).Value = SEARCHSTRINGS(c, Sheets("Categories").Range("A:A").SpecialCells(xlConstants), ",", True)
        Next c
    
        Range("D3") = "4. Select Category"
    End Sub
    
    Function SEARCHSTRINGS(cel As Range, rngTBL As Range, _
        Optional Delim As String, Optional NoDUPE As Boolean) As String
        Dim r As Range, BUF As String
    
    Set cel = cel.Cells(1)          'in case more than one cell is put in first parameter
    If Delim = "" Then Delim = ","
    
        For Each r In rngTBL
            If InStr(cel, r) > 0 Then
                If NoDUPE Then
                    If InStr(BUF, r) = 0 Then BUF = BUF & r & ", "
                Else
                    BUF = r & ", "
                End If
            End If
        Next r
        
        If BUF <> "" Then
            SEARCHSTRINGS = Left(BUF, Len(BUF) - 2)
        Else
            SEARCHSTRINGS = "none found"
        End If
    
    End Function
    Last edited by JBeaucaire; 01-28-2012 at 12:26 AM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  9. #9
    Registered User
    Join Date
    01-26-2012
    Location
    Paul Green
    MS-Off Ver
    Microsoft Excel 2008 for Mac
    Posts
    8

    Re: if cell contains a specific text, then put that specific text into a different ce

    Hi Jerry, you are a wonderfully generous person.

    I was following you up to the point of SUMIF. I am so out of my league, I can't even find the file that you have updated with said formulae and macro buttons, etc.

    I will have a go.

    Many thanks for your time and generous spirit

  10. #10
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,228

    Re: if cell contains a specific text, then put that specific text into a different ce

    The stupid forum won't let me attach a file, something's broke.

    Here's a link to my file drop box on my code site. Your file is down in the USER FILES.

    FILES
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0