+ Reply to Thread
Results 1 to 11 of 11

Ignoring Blank Cells in IF statement

  1. #1
    Registered User
    Join Date
    08-10-2009
    Location
    Kansas, USA
    MS-Off Ver
    Excel 2007
    Posts
    3

    Ignoring Blank Cells in IF statement

    Here's my problem.

    I've got four columns of data. The first column contains pricing for a bunch of products from our company. The other three columns contain pricing for three other competitors. So for example:

    Product | Our Price | Comp1 Price | Comp2 Price | Comp3 Price
    Gloves | $4.59 | $5.00 |$6.00 | $3.56
    Hats | $5.00 | | | $4.59

    In column G right after Comp3 Price I have an IF statement that says if Comp1 Price is less than Comp2 Price, Comp3 Price, and Our Price, to print "Comp3" in that cell. If it is not less than the comparable data, then check Comp2 Price then Comp3 price in the same fashion. If Comp1, Comp2, or Comp3 is not less than Our Price then print "My Company Name." This will allow me to see who has the lowest price for that product and also tell me if that lowest price is lower than our price.

    My problem is that I can't get it to work out so Excel ignores blank cells. So for example, Comp3 has the lowest price amongst our competitors for hats and is also lower than ours. But when I check for Comp3 price being lower than Comp1 and Comp2, it comes back as negative because Excel sees those cells as zeroes even though they're blank. My formula is:

    =IF(AND(C2<D2,C2<E2,C2<B2),"COMP1",IF(AND(D2<E2,D2<C2,D2<B2),"COMP2",IF(AND(E2<C2,E2<D2,E2<B2),"COMP3","MYCOMPANY")))

    This would do exactly what I need Excel to do if it would ignore the blank cells. The problem is that Comp3 has pricing for hats because they offer hats, but comp1 and Comp2 don't offer hats at all, so naturally Comp3 has the lowest price; however, according to Excel Comp1 and Comp2 have the lowest price because the cells are blank and counted as zeroes.

    So, does anyone know how to work this out so Comp3 will be counted as the lowest price for hats, ignoring the blank cells of Comp1 and Comp2?
    Last edited by dbanbury; 08-12-2009 at 12:11 PM. Reason: Problem solved.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Ignoring Blank Cells in IF statement

    It sounds to me as though you want:

    =INDEX($B$1:$E$1,MATCH(MIN($B2:$E2),$B2:$E2,0))
    copied down

    If you want MYCOMPANY instead of OurPrice then either change B1 to "MYCOMPANY" or encase the above within a Substitute, eg:

    =SUBSTITUTE(INDEX($B$1:$E$1,MATCH(MIN($B2:$E2),$B2:$E2,0)),$B$1,"MYCOMPANY")

    I would probably opt to change B1 myself...

  3. #3
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Ignoring Blank Cells in IF statement

    You can use this to return the lowest price
    =INDEX(B2:E2,1,MATCH(SMALL(B2:E2,1),B2:E2,0))

    And in an adjacent column return the "Company"
    =INDEX($B$1:$F$1,1,MATCH(SMALL($B2:$E2,1),$B2:$F2,0),1)

    You'll see the price and name together as you extend down the column.

  4. #4
    Forum Contributor
    Join Date
    01-21-2005
    Location
    Colorado
    MS-Off Ver
    2000,2003,2007
    Posts
    481

    Re: Ignoring Blank Cells in IF statement

    Give this a try

    =IF(MIN(B2:E2)=B2,B$1,IF(MIN(B2:E2)=C2,C$1,IF(MIN(B2:E2)=D2,D$1,IF(MIN(B2:E2)=E2,E$1))))

    I have this formula referencing the cell in the first column (B$1) so that you won't have to type the company names in the formula. That way if you change the column label it will automatically update the result of your formula as well.

    You can easily modify this to find the company with the highest price as well by replacing MIN with MAX and then double checking the cell references are correct.

  5. #5
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Ignoring Blank Cells in IF statement

    i think donkyotes first one is the way to go with changing B1 to "my company"
    the others are over engineered!
    i was going to suggest similar
    =INDEX($B$1:E2,1,MATCH(MIN($B2:$E2),$B2:$E2,0)) but there is no need to change the first bit $B$1:E2
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Ignoring Blank Cells in IF statement

    Thanks Martin,

    Yes I would say if you wanted to return the lowest price a standard MIN($B2:$E2) would be sufficient (the blanks will not be coerced to 0) ... and when using INDEX with a Vector as opposed to a Matrix there's no need to specify both row & column - either/or as appropriate will suffice.

  7. #7
    Registered User
    Join Date
    08-10-2009
    Location
    Kansas, USA
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Ignoring Blank Cells in IF statement

    To those who responded, thank you and I apologize for not posting a response sooner. I didn't realize this board would move so fast.

    These solutions work great and do exactly what I need; however, the way the sheet is organized, I have our pricing next to the product itself, then in the next columns over I have "Units Sold," "Sales," etc. and THEN competitor pricing. So basically, we're talking about column D having our pricing and then P:R having the three competitors pricing. I simplified the problem for explanatory purposes hoping I didn't need to delve much deeper than that, but the problem I am coming across is that without having our pricing next to the competitors (I have logic behind my organization, trust me ) I can't put a range. So MIN(D2:R2) for example won't work. I have to individually select D2 to include with P2:R2 and I'm not sure how to incorporate this into Donkey's formula, which is exactly what I want. Can MIN be modified to include column D in addition to P:R? And if so, will the formula still bypass the empty cells (including any empty cells under D)?

    Now, I could just move the columns so they're all next to each other and just put D:G, like I did in the example above, but I want to figure out if this is possible first before I rearrange my data.

    If this is an easy fix I apologize for my lack of function knowledge in advance.

  8. #8
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Ignoring Blank Cells in IF statement

    only way is for us to see workbook concerned

  9. #9
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Ignoring Blank Cells in IF statement

    Can MIN be modified to include column D in addition to P:R?
    MIN can accept non-contiguous ranges if that's what you mean, eg:

    =MIN(D2,P2:R2)

    but of course the MATCH function can not, meaning the above approach can not be used in conjunction with the INDEX/MATCH to retrieve the header (as the MATCH can not accept a non-contiguous range).

    The most obvious solution so as to be able to retrieve the header whilst simultanesouly avoiding inefficient formulae would be to add D contents to S (if viable) that it to say create one contiguous range... if this is not possible let us know.

  10. #10
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Ignoring Blank Cells in IF statement

    One approach for handling non-contiguous range might be:

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    08-10-2009
    Location
    Kansas, USA
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Ignoring Blank Cells in IF statement

    Donkey:

    Your solution works perfectly! It's amazing how something that sounds so simple can turn into something that complicated (complicated for me at least), but your idea of copying the data from D and placing it in an adjacent column to the competitor pricing would have worked out as well and for some reason I hadn't thought of that. But this formula is great and I appreciate your help and all the other responses I received. I'm very glad I came to this forum.

+ 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