+ Reply to Thread
Results 1 to 14 of 14

If value is text1, put text2 in new cell

  1. #1
    Registered User
    Join Date
    11-03-2012
    Location
    CO, USA
    MS-Off Ver
    Excel 2013
    Posts
    26

    Question If value is text1, put text2 in new cell

    Using Excel 2007. I have a column with text in each cell, and depending on what the text is within the range, want Excel to automatically enter different text in the adjacent cell.

    For example, within the range of A2:A5, if Excel finds "apple" in cell A2, it enters "red" in cell B2. If Excel finds "grape" in the range A2:A5, it enters "green" in cell B4.

    Row --Col A -- Col B
    2 --apple -- red
    3 --apple -- red
    4 --grape -- green
    5 --kiwi ---green

    Thanks for your help.
    Last edited by Lis7; 11-24-2012 at 10:34 PM.

  2. #2
    Forum Expert Moo the Dog's Avatar
    Join Date
    09-28-2012
    Location
    Wisconsin
    MS-Off Ver
    Office 365 (PC & Mac)
    Posts
    1,845

    Re: If value is text1, put text2 in new cell

    Well, if you are just using the three possibilities, you could use:

    In B2 then fill down: =IF(A2="apple","Red",IF(OR(A2="grape","kiwi"),"green","No Match"))

    - Moo

  3. #3
    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,929

    Re: If value is text1, put text2 in new cell

    if it is as simple as you describe (just apple, grape, red, green), then try using this...
    =IF(A1="Apple","Red",IF(A1="grape","green",""))

    However, I doubt that you're needs are quite that simple? If nbot, then I think you need to set up a table with you're "choices" in it - red, green etc

    so, assuming your're data is in A1:A5, and you're "choices are in F1:G3 (adjused as needed), then create a vlookup as shown below.
    =VLOOKUP(A1,$F$1:$G$3,2,FALSE)
    the "choice" table would look something like this...

    apple red
    grape green
    kiwi green
    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

  4. #4
    Forum Expert Moo the Dog's Avatar
    Join Date
    09-28-2012
    Location
    Wisconsin
    MS-Off Ver
    Office 365 (PC & Mac)
    Posts
    1,845

    Re: If value is text1, put text2 in new cell

    You could also use the LOOKUP function:

    =LOOKUP(A2,{"apple","grape","kiwi"},{"red","green","green"})

    - Moo

  5. #5
    Registered User
    Join Date
    11-03-2012
    Location
    CO, USA
    MS-Off Ver
    Excel 2013
    Posts
    26

    Re: If value is text1, put text2 in new cell

    Is there a limit to how many conditions can be put after the "IF"?

  6. #6
    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,929

    Re: If value is text1, put text2 in new cell

    you can nest a max of 7 if()'s, thats why I suggested a vlookup table in post #3

  7. #7
    Forum Expert Moo the Dog's Avatar
    Join Date
    09-28-2012
    Location
    Wisconsin
    MS-Off Ver
    Office 365 (PC & Mac)
    Posts
    1,845

    Re: If value is text1, put text2 in new cell

    Excel 2007 allows up to 64 nested IF statements... however, if you need to match more than 4 or 5 items, it makes better sense to go with a lookup table as FDibbins suggested. See my attached file for an example.

    - Moo
    Attached Files Attached Files

  8. #8
    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,929

    Re: If value is text1, put text2 in new cell

    @ Moo....64??

  9. #9
    Forum Expert Moo the Dog's Avatar
    Join Date
    09-28-2012
    Location
    Wisconsin
    MS-Off Ver
    Office 365 (PC & Mac)
    Posts
    1,845

    Re: If value is text1, put text2 in new cell

    Duplicate post.. grr
    Attached Files Attached Files

  10. #10
    Forum Expert Moo the Dog's Avatar
    Join Date
    09-28-2012
    Location
    Wisconsin
    MS-Off Ver
    Office 365 (PC & Mac)
    Posts
    1,845

    Re: If value is text1, put text2 in new cell

    FDibbins, yes, Excel 2007+ allows 64 nested levels. If you would like to try it, open a worksheet and enter the letter 'a' in cell A1. Then in another cell enter:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    That is a 10-level IF statement, and works just fine.

    - Moo

  11. #11
    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,929

    Re: If value is text1, put text2 in new cell

    @ Moo. hmm ok, you learn something new every day, thanks

  12. #12
    Forum Expert Moo the Dog's Avatar
    Join Date
    09-28-2012
    Location
    Wisconsin
    MS-Off Ver
    Office 365 (PC & Mac)
    Posts
    1,845

    Re: If value is text1, put text2 in new cell

    @ FD - no problem.. that learning something new everyday thing is contagious!

    Also... I'm hoping the answers we've provided have solved the OP's issue.

    - Moo

  13. #13
    Registered User
    Join Date
    11-03-2012
    Location
    CO, USA
    MS-Off Ver
    Excel 2013
    Posts
    26

    Re: If value is text1, put text2 in new cell

    Thanks FDibbins and Moo!

  14. #14
    Forum Expert Moo the Dog's Avatar
    Join Date
    09-28-2012
    Location
    Wisconsin
    MS-Off Ver
    Office 365 (PC & Mac)
    Posts
    1,845

    Re: If value is text1, put text2 in new cell

    You're quite welcome, Lis7. Glad we could help!

+ 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.6.0 RC 1