+ Reply to Thread
Results 1 to 3 of 3

easy IF statement

  1. #1
    Registered User
    Join Date
    03-12-2007
    Posts
    3

    easy IF statement

    Hello all,

    I have a feeling that this is going to be an easy (ish) question, so posted in the new users section.

    i am wanting to define the content of a cell, dependant on what exists in another cell.

    in simple terms,
    i want cell A1 to display 'Fruit' if cell A2 contains 'Apple', 'Banana', or 'Grape'.
    cell A1 should display 'Vegetable' if cell A2 contains 'Potato', 'Carrot', or 'Swede'.

    cell A2 can contain more than one value, but only fruit OR veg - ie could contain "Banana Apple", but not "Potato Grape".

    so far I have this simple formula, in cell A1

    =(IF(A2 = "APPLE", "FRUIT", "VEGETABLE"))

    but this does not cater for anything much.

    Any help would be greatly appreciated.

    Thanks, Mark

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,902
    If you have 2 ranges named Fruits and Vegetables, respectively and each containing the items for the categories, then you can use something like:

    =IF(ISNUMBER(MATCH(A2,fruits,0)),"Fruit",IF(ISNUMBER(MATCH(A2,Vegetables,0)),"Vegetable",""))

    you can also just replace fruits and vegetables with ranges containing respective items.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Forum Contributor
    Join Date
    03-14-2006
    Location
    Pakistan
    Posts
    1,791

    Lightbulb

    Quote Originally Posted by 1978
    Hello all,

    I have a feeling that this is going to be an easy (ish) question, so posted in the new users section.

    i am wanting to define the content of a cell, dependant on what exists in another cell.

    in simple terms,
    i want cell A1 to display 'Fruit' if cell A2 contains 'Apple', 'Banana', or 'Grape'.
    cell A1 should display 'Vegetable' if cell A2 contains 'Potato', 'Carrot', or 'Swede'.

    cell A2 can contain more than one value, but only fruit OR veg - ie could contain "Banana Apple", but not "Potato Grape".

    so far I have this simple formula, in cell A1

    =(IF(A2 = "APPLE", "FRUIT", "VEGETABLE"))

    but this does not cater for anything much.

    Any help would be greatly appreciated.

    Thanks, Mark
    Hi try this in A1

    =IF(AND(A2<>"",ISERROR(SEARCH("Potato",A2)),ISERROR(SEARCH("Carrot",A2)),ISERROR(SEARCH("Swede",A2))),"Fruit","Vegitable")

    this formula assumes that you enter fruit or vergitable names in a single cell A2 (may be seperated with commas)
    and you do not enter anything other than fruit names or vegitable names.

+ 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