+ Reply to Thread
Results 1 to 7 of 7

Greater than in if statements?

  1. #1
    Registered User
    Join Date
    08-28-2011
    Location
    Tennessee
    MS-Off Ver
    Excel 2003
    Posts
    14

    Greater than in if statements?

    It seems to want to reference a cell when I use ">"

    I basically want it to say
    =IF(calculate!K21=0, " ", if( calculate!K21>12:59:59, calculate!K21-12:00:00, calculate!K21))
    but it says there's an error

    That way I can have the cells always return 12 hour increments instead of military time and return nothing but a space if there's a zero value in the referenced cell.
    Last edited by IRMacGuyver; 09-13-2011 at 07:51 PM.

  2. #2
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: can you do greater than in if statements?

    You have to put the time in quotes or use TIME function, something like this

    =IF(calculate!K21=0,"",calculate!K21-IF(calculate!K21>"12:59:59"+0,"12:00",0))

    Note: I used a blank "", rather than a space " " - which is more usual practice
    Audere est facere

  3. #3
    Registered User
    Join Date
    08-28-2011
    Location
    Tennessee
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: can you do greater than in if statements?

    ah thank you much

    Is there any reason you added the "+0"?

  4. #4
    Registered User
    Join Date
    08-28-2011
    Location
    Tennessee
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: can you do greater than in if statements?

    I used =IF(calculate!K21=0, " ", IF( calculate!K21>"12:59", calculate!K21-"12:00", calculate!K21))
    and it stayed 13:00
    Then I tried =IF(calculate!K21=0, " ", IF( calculate!K21>"12:59", calculate!K21, calculate!K21-"12:00"))
    and that worked for times over 12:59 but broke when the times were under 12:59
    The whole point is that I'm trying to get rid of military time

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

    Re: can you do greater than in if statements?

    Military time is a formatting decision, not a cell value. If you select cell K21, press CTRL-1, you can change the display format to TIME > 1:30 PM and you'll have the same results without another cell.
    _________________
    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!)

  6. #6
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: can you do greater than in if statements?

    Jerry is right, of course, you might be better off with some formatting rather than changing the values but to answer your question.........Yes, you need the +0 (or something similar)

    "12:59:59" in quotes is just text unless you perform some sort of calculation on it (that doesn't change the value) like +0 or *1....that "coerces" it to a TIME value. The formula I suggested should do what you want........or you can just use numbers - a day in excel = 1 so 12 hours = 0.5, 13 hours = 13/24 etc. so.....

    =IF(calculate!K21=0,"",calculate!K21-IF(calculate!K21>13/24,0.5,0))

  7. #7
    Registered User
    Join Date
    08-28-2011
    Location
    Tennessee
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: can you do greater than in if statements?

    Quote Originally Posted by JBeaucaire View Post
    Military time is a formatting decision, not a cell value. If you select cell K21, press CTRL-1, you can change the display format to TIME > 1:30 PM and you'll have the same results without another cell.
    But then it will display the AM/PM and I need to save room and simplify it visually by dropping that.

    Okay I see why you added the +0 but when the reference cell has a word instead of a time that equation breaks. I also don't quiet get the ',"12:00",0' part.

    EDIT oh I think I get why you're doing that now. It's part of the equation to add to the base reference.
    Last edited by IRMacGuyver; 09-13-2011 at 09:22 PM.

+ 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