+ Reply to Thread
Results 1 to 10 of 10

IF statement that differentiates between blank and zero

  1. #1
    Registered User
    Join Date
    03-04-2017
    Location
    NY, NY
    MS-Off Ver
    2016
    Posts
    18

    IF statement that differentiates between blank and zero

    Hi All,
    I am calculating sales of lottery tickets. Each ticket has a ticket number, and when our store manager enters the start and end ticket numbers for the day, Excel should show the $ amount sold. It's easy enough with New York's Lotto, because a book of 100 tickets starts at number 100 and ends at number 1, so 0 tickets means there are zero left. In Massachusetts a book of 100 tickets starts at 99 and the last ticket is #0. (seems stupid, but maybe there's a reason)

    My issue is that the formula that I've come up with so far to calculate the $ sold is: =IF(ISTEXT(B5),(A5+1)*A$2,IF(B5>0,(A5-B5)*A$2,A5*A$2)) If the start ticket # is 10 and the end ticket # is 5, then 5 were sold and at $5 a ticket the total is $25. If the end ticket is 0, then one ticket is left and 10 were sold, so the $ sold is $50. If all of the tickets were sold I will need them to enter some sort of text in the cell, since 0 doesn't mean 0 are left. That's why I'm checking for text.

    My spreadsheet is very large, with lots of blank cells. The formula works ok, except that if I change the formula to check if the cell=0, then it calculates the blank cells as if they were zero, even though they are actually blank, so for blanks it calculates as if there is one ticket left.

    One solution would be to have the manager enter -1 when they are all sold, which I assume would work, but it's not a very elegant solution, since -1 doesn't really make any sense. I assume I could use VBA instead of a formula to check if there is any text in the cell, but I'm wondering if there is a non-vba solution.

    Here is the results with the current formula: (see the file attached)

    Ticket Value
    $5.00

    Start Ticket # End Ticket # $ Sold
    10 5 $25.00
    10 0 $50.00
    10 x $55.00
    10 4 $30.00
    10 8 $10.00
    10 $50.00
    Attached Files Attached Files
    Last edited by Tambe257; 03-04-2017 at 12:09 PM.

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

    Re: IF statement that differentiates between blank and zero

    Let us see your formula.


    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    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.

  3. #3
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: IF statement that differentiates between blank and zero

    Although you could use the ISBLANK() function...

    =IF(ISBLANK(A1),"blank",IF(A1=0,"zero","other"))

    Will return 'blank' if a cell really is blank,0 if it contains 0 or 'other' if it contains something else.

  4. #4
    Registered User
    Join Date
    03-04-2017
    Location
    NY, NY
    MS-Off Ver
    2016
    Posts
    18

    Re: IF statement that differentiates between blank and zero

    Thanks for the suggestions. I didn't see the way to add the attachment, so I edited above to now include an example file.

  5. #5
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,171

    Re: IF statement that differentiates between blank and zero

    Try

    =IF(ISNUMBER(B5),(A5-B5)*$A$2,IF(B5="x",(A5+1)*$A$2,""))

  6. #6
    Registered User
    Join Date
    03-04-2017
    Location
    NY, NY
    MS-Off Ver
    2016
    Posts
    18

    Re: IF statement that differentiates between blank and zero

    Quote Originally Posted by cytop View Post
    Although you could use the ISBLANK() function...

    =IF(ISBLANK(A1),"blank",IF(A1=0,"zero","other"))

    Will return 'blank' if a cell really is blank,0 if it contains 0 or 'other' if it contains something else.
    I modified your suggestion of ISBLANK to make it work if there is >0 or text entered:

    =IF(ISTEXT(B15),(A15+1)*A$2,IF(ISBLANK(B15),0,IF(B15=0,A15*A$2,IF(B15>0,(A15-B15)*A$2,"Invalid"))))

    Thanks for the help!

  7. #7
    Registered User
    Join Date
    03-04-2017
    Location
    NY, NY
    MS-Off Ver
    2016
    Posts
    18

    Re: IF statement that differentiates between blank and zero

    Quote Originally Posted by JohnTopley View Post
    Try

    =IF(ISNUMBER(B5),(A5-B5)*$A$2,IF(B5="x",(A5+1)*$A$2,""))
    The issue with this is that if the number entered is 0, then there is one ticket left and the total should be A5*A2. (10 tickets sold x $5)

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

    Re: IF statement that differentiates between blank and zero

    Paste in C5 and then fill down

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


    Use 0 when outside Mass otherwise use a blank

  9. #9
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,171

    Re: IF statement that differentiates between blank and zero

    if B5 =0 then 10-0 =10 * 5 = 50!!!!!!

    Did you actually try it????

  10. #10
    Registered User
    Join Date
    03-04-2017
    Location
    NY, NY
    MS-Off Ver
    2016
    Posts
    18

    Re: IF statement that differentiates between blank and zero

    Quote Originally Posted by JohnTopley View Post
    if B5 =0 then 10-0 =10 * 5 = 50!!!!!!

    Did you actually try it????
    Sorry, you're absolutely right. I did try it, but I had a typo. Well done.

+ 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. IF Statement to leave cell blank if multiple cells are all blank
    By sweeteri in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 03-14-2014, 12:02 PM
  2. [SOLVED] If two cells are blank, if statement to show third statement is blank
    By juliewoo in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-20-2013, 12:28 PM
  3. [SOLVED] if statement, is blank statement
    By cherryt in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-01-2013, 09:30 AM
  4. Average Between Dates, differentiates between text
    By TheGenericGeek in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-15-2013, 01:18 AM
  5. [SOLVED] Combining If Statement, Is Blank Statement and HLookUp
    By kimberlyre2000 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-29-2012, 01:27 PM
  6. Excel Function that differentiates "male" from "female" names with 900+ names
    By doylehargrove in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-17-2012, 06:00 PM
  7. [SOLVED] If statement that copies text from a separate worksheet, or if blank, leaves cell blank.
    By barleycorn in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-22-2012, 12:30 PM

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