+ Reply to Thread
Results 1 to 10 of 10

IF this text, then This number

  1. #1
    Registered User
    Join Date
    04-16-2015
    Location
    Las Vegas
    MS-Off Ver
    2010
    Posts
    4

    IF this text, then This number

    I have one cell that contains up to 26 different 3 letter facility prefixes, and they are part of 4 different locations with a number code. Example, ASK is part of Facility code 20. I want a formula that will look at cell M and if it the facility belongs to code 18, 20, 21, or 22, it will put that number in Cell N.

    I tried to just repeat this formula 26 times in Column N, but Excel says I have too many arguments.

    =IF(M2="ASK","20")

    here's my first attempt with the 8 codes that belong to #20:

    =IF(M2="ASK","20",IF(M2="BOI","20"),IF(M2="SPO","20"),IF(M2="WHC","20"),IF(M2="WAL","20"),IF(M2="ROS","20"))

  2. #2
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: IF this text, then This number

    If I understand you're first attempt right this formula should do the trick:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Last edited by Tsjallie; 04-16-2015 at 04:15 PM. Reason: edited formula
    Cheers!
    Tsjallie




    --------
    If your problem is solved, pls mark the thread SOLVED (see Thread Tools in the menu above). Thank you!

    If you think design is an expensive waste of time, try doing without ...

  3. #3
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: IF this text, then This number

    Try using Match to return a number

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Will return 2 because "b" is the second entry in the array.

    Now you can use choose to get your final value

    so

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Will return 4 because 4 is the second data entry

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Will return 6 because 6 is the third data entry.

    So putting those together

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    If M2 = "BOI" then this formula will return 19
    Last edited by mehmetcik; 04-16-2015 at 05:00 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  4. #4
    Registered User
    Join Date
    04-16-2015
    Location
    Las Vegas
    MS-Off Ver
    2010
    Posts
    4

    Re: IF this text, then This number

    When I tried that, the result in column N became 0. if the text in cell M is either of those, I want the result to be 20. then I want to also add a condition that if the text equals other facilities, I want the text to be 21 and so on.

  5. #5
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: IF this text, then This number

    You can use the sumproduct-formula for any condition and then summing it.
    Example:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    If none of the conditions are true then the result will be 0. You can avoid showing this 0 by formatting the cell as "#" so it doesn't show the 0.

  6. #6
    Registered User
    Join Date
    04-16-2015
    Location
    Las Vegas
    MS-Off Ver
    2010
    Posts
    4

    Re: IF this text, then This number

    Thanks.... the formlul =MIN(SUMPRODUCT(--(M2={"ASK";"BOI";"SPO";"WHC";"WAL";"ROS"})),1)*20

    worked, except I guess I forgot to mention that I have 4 conditions; If M2 = any of those ones I want it to come back with 20, but if it equals any of the other conditions, I want it to come back with those numbers...but how do I put the four conditions together without overwhelming Excel? See, I have either of these conditions and I need them to put the # in cell N...

    =MIN(SUMPRODUCT(--(M2={"ASK";"BOI";"SPO";"WHC";"WAL";"ROS"})),1)*20
    =MIN(SUMPRODUCT(--(M2={"SNV";"LOM";"LBH";"SDI";"WLA"})),1)*22
    =MIN(SUMPRODUCT(--(M2={"WTX";"NMX";"NAZ";"AMA";"PHO";"ELP";"ELP"})),1)*18
    =MIN(SUMPRODUCT(--(M2={"PAL";"HON";"NCA";"SFR";"CCA";"SIE"})),1)*21

  7. #7
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: IF this text, then This number

    The best bet is to build a lookup table in an available area, say O2:P25
    O2:O25 = Ask Boi Spo Whc etc...
    P2:P25 is their corresponding Group #s, 18, 20,21,22 etc..

    Then
    =VLOOKUP(M2,$O$2:$P$25,2,FALSE)


    This makes it so much easier to add/remove/edit items from the groups..

  8. #8
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: IF this text, then This number

    You can loose the MIN-part. Not necessary.
    You can put the conditions together by summing them.
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    This won't overwhelm Excel. But alternatively you could put the strings and their number in a table to make it more flexible and the formula somewhat smaller.

  9. #9
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: IF this text, then This number

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    04-16-2015
    Location
    Las Vegas
    MS-Off Ver
    2010
    Posts
    4

    Re: IF this text, then This number

    Thanks Everyone, both Tsjallie and mehmetcik, your suggestions worked.

    I need to learn more about Vlookup though, that seems more flexible f

+ 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. Replies: 5
    Last Post: 11-30-2014, 07:56 AM
  2. [SOLVED] Formula to count the number of spaces before text/number is written in a cell.
    By kmis in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 06-12-2013, 05:05 PM
  3. Replies: 6
    Last Post: 01-31-2013, 02:50 AM
  4. Replies: 6
    Last Post: 07-29-2008, 03:23 PM
  5. Replies: 1
    Last Post: 07-29-2005, 04:05 PM

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