+ Reply to Thread
Results 1 to 9 of 9

Formula for checking a cell and determining data set based on cell value

  1. #1
    Registered User
    Join Date
    05-18-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    3

    Question Formula for checking a cell and determining data set based on cell value

    Hey guys. Long time lurker, first time poster. I wasn't able to find this after searching so I figured I'd ask y'all.

    G8 needs to check if D2 has the user input "Y" or "N" for yes or no in it.

    If "N", it needs to check the value in G5. A value from 0 to 350 needs to return 250. From 351 to 600 needs to return 500. 601 to 1100 needs to return 1000. 11, it 1 to 2100 needs to return 2000. 2101 to 3100 needs to return 3000. 3101 to 5100 needs to return 5000. 5101 to 10100 needs to return 10000. Anything higher than 10100 needs to say "ERROR".

    If "Y" it needs to check the value in G5 again. A value from 0 to 600 needs to return 500. 601 to 1100 needs to return 1000. 1101 to 2100 needs to return 2000. 2101 to 3100 needs to return 3000. 3101 to 5100 needs to return 5000. 5101 to 10100 needs to return 10000. 10101 to 20100 needs to return 20000. 20101 to 40100 needs to return 40000. Anything higher than 40100 needs to say "ERROR"

    I tried a few formulas but just kept getting confused. Do I need to search D2 for "Y" or "N" and point it to a table of values or?.... An explanation would be helpful. Thanks in advance!

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Formula for checking a cell and determining data set based on cell value

    First base formula:
    =IF(D2="N", LOOKUP(G5, {0,351,601,1101,2101,3101,5101,10101}, {250,500,1000,2000,3000,5000,10000,"ERROR"})

    Second base formula:
    =IF(D2="Y", LOOKUP(G5, {0,601,1101,2101,3101,5101,10101,20101,40101}, {500,1000,2000,3000,5000,10000,20000,40000,"ERROR"}))


    Merged into one long formula:

    =IF(D2="N", LOOKUP(G5, {0,351,601,1101,2101,3101,5101,10101}, {250,500,1000,2000,3000,5000,10000,"ERROR"}), IF(D2="Y", LOOKUP(G5, {0,601,1101,2101,3101,5101,10101,20101,40101}, {500,1000,2000,3000,5000,10000,20000,40000,"ERROR"}), ""))
    _________________
    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!)

  3. #3
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Formula for checking a cell and determining data set based on cell value

    Create 2 tables, 1 for Y and the other for N...

    The table for N would look like this:

    0......350......250
    351...600......500
    601...1100....1000
    1101..2100....2000
    2101..3000....3000
    3101..5100....5000
    5101..10100...10000

    Assume that table is in the range I2:K8

    The table for Y would look like this:

    0.........600.........500
    601.....1100........1000
    1101....2100.......2000
    2101....3100.......3000
    3101....5100.......5000
    5101....10100.....10000
    10101...20100....20000
    20101...40100....40000

    Assume that table is in the range I11:K18

    Then, this formula entered in G8:

    =IF(AND(D2="N",ISNUMBER(G5)),IF(G5>10100,"Error",LOOKUP(G5,I2:K8)),IF(AND(D2="Y",ISNUMBER(G5)),IF(G5>40100,"Error",LOOKUP(G5,I11:K18)),""))
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Formula for checking a cell and determining data set based on cell value

    I like Tony's idea of an easily editable lookup table, but since your tables would be so similar, I believe a single table will work and allow an INDEX/MATCH to work.

    \1

    Please Login or Register  to view this content.
    This shows a single table M1:O11, which then allows this formula to do the job:

    =INDEX($N$2:$O$11, MATCH(G5, $N$2, 1), MATCH(D2, $N$1:$O$1, 0))

  5. #5
    Registered User
    Join Date
    05-18-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Formula for checking a cell and determining data set based on cell value

    Wow, first response in 33 minutes! You guys are awesome. I won't need to be editing the values, so JBeaucaire's first response will work for me. I tested it in my table(edit: should've said spreadsheet) and it works flawlessly. If I ever need to edit the values, I'll look into implementing Tony's solution. I owe you guys both a beer! Thanks again! Marking as solved.
    Last edited by fauxreality; 05-18-2013 at 11:34 AM.

  6. #6
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Formula for checking a cell and determining data set based on cell value

    Make mine St. Pauli Girl Dark.

    Thanks for the feedback!

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Formula for checking a cell and determining data set based on cell value

    Coke Zero and some Cheetos... yeah, that's me.

    (stares down at multicolored keyboard...didn't used to be multicolored)
    Last edited by JBeaucaire; 05-18-2013 at 04:33 PM.

  8. #8
    Registered User
    Join Date
    05-18-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Formula for checking a cell and determining data set based on cell value

    Sorry, not sure how to do that. I will glady give you both a virtual thumbs up if ya tell me how

  9. #9
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Formula for checking a cell and determining data set based on cell value

    You've already done it!

+ 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