+ Reply to Thread
Results 1 to 22 of 22

Trouble with an IF statement

  1. #1
    Forum Contributor
    Join Date
    05-24-2010
    Location
    London England
    MS-Off Ver
    Excel 2003
    Posts
    345

    Trouble with an IF statement

    Hi,

    I'm having trouble with the following.

    I want to do a formula that says,

    if cell k68 is equal to or less than 09:00, then write "0", otherwise, 09:00-time in cell k68

    I did the following formula but it didn't work. either because of incorrect syntax or possibly formatting issues

    Please Login or Register  to view this content.
    Last edited by floricita; 09-06-2011 at 09:14 AM. Reason: addition

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Trouble with an IF statement

    Try

    =IF(K68<=--"09:00",0,K68-"09:00")

  3. #3
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Trouble with an IF statement

    First check to see if the content of K68 is time or text looking like time

    To do this enter =istext(K68) in some cell. If FALSE, you have real time, if TRUE, text looking like time

    If real time, I suggest entering 09:00 in a cell somewhere ( say X1) wujch will allow flexibility

    Then use the following :
    Please Login or Register  to view this content.
    If K68 is text, let me know

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Trouble with an IF statement

    Hi flocicita,

    I believe you have two problems with your formula. First it is circular ref as you can't change something based on the same cell. Second I believe you need to use TimeValue("09:00") instead of what you have.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  5. #5
    Forum Contributor
    Join Date
    05-24-2010
    Location
    London England
    MS-Off Ver
    Excel 2003
    Posts
    345

    Re: Trouble with an IF statement

    Thanks guys.

    None of the above seems to work though-doesn't seem to return 0, if it is equal to or less than 09:00

  6. #6
    Forum Contributor
    Join Date
    05-24-2010
    Location
    London England
    MS-Off Ver
    Excel 2003
    Posts
    345

    Re: Trouble with an IF statement

    Hi Yes it is text.

  7. #7
    Forum Contributor
    Join Date
    05-24-2010
    Location
    London England
    MS-Off Ver
    Excel 2003
    Posts
    345

    Re: Trouble with an IF statement

    Should I try highlighting cells, format-time (hopefully stay the same)-then repeat what you suggested?

  8. #8
    Forum Contributor
    Join Date
    05-24-2010
    Location
    London England
    MS-Off Ver
    Excel 2003
    Posts
    345

    Re: Trouble with an IF statement

    Right, I changed the format of the cells from custom (text) to time, and did your formula.

    It works if it is greater or equal to 09:00 but for values (times) that are less, it doesn't return the 0 that I wanted, instead just a string of ######## because the date is negative value, even though I wanted it returned as 0 value.

    any help would be great

    Thanks

  9. #9
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Trouble with an IF statement

    Maybe post a small sample of your data in a worksheet

  10. #10
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Trouble with an IF statement

    After you changed the format, re-type the entry in K68. It (Bob's formula) should then work.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  11. #11
    Forum Contributor
    Join Date
    05-24-2010
    Location
    London England
    MS-Off Ver
    Excel 2003
    Posts
    345

    Re: Trouble with an IF statement

    Right, I have copied and pasted visible cells of what I could see originally, without changing any formats or anything
    Attached Files Attached Files

  12. #12
    Forum Contributor
    Join Date
    05-24-2010
    Location
    London England
    MS-Off Ver
    Excel 2003
    Posts
    345

    Re: Trouble with an IF statement

    Quote Originally Posted by NBVC View Post
    After you changed the format, re-type the entry in K68. It (Bob's formula) should then work.
    Hi I did that and it works, if it is equal to or greater than 09:00, but if it isn't (first part of if statement, it doesn't return the 0 that I wanted. Just #######

  13. #13
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Trouble with an IF statement

    It must still be text, because only text entry will result in negative values as far as I can see.

    Try selecting the cell, go to Data|Text to Columns and just click Finish. Does that change anything?

  14. #14
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Trouble with an IF statement

    Also, not sure if you noticed that Bob's formula rearranged the second part of the formula as, your request:
    if cell k68 is equal to or less than 09:00, then write "0", otherwise, 09:00-time in cell k68
    doesn't really make sense... you can't do 9:00 - time because you stated if time < 9:00 then 0... so if time is greater than 9:00 you will get negative.

  15. #15
    Forum Contributor
    Join Date
    05-24-2010
    Location
    London England
    MS-Off Ver
    Excel 2003
    Posts
    345

    Re: Trouble with an IF statement

    Quote Originally Posted by NBVC View Post
    Also, not sure if you noticed that Bob's formula rearranged the second part of the formula as, your request: doesn't really make sense... you can't do 9:00 - time because you stated if time < 9:00 then 0... so if time is greater than 9:00 you will get negative.
    The text to columns thing didn't work.

    with regards to that- basically col K is saying what times shops will open, however, we don't want shops to open no later than 09:00, so all those that are later than 09:00 I want the difference in col L and then total at the end and then also do some subsequent horizontal equations also.

    So in col L I basically need the differences between 09:00 and the time in K, but if col K already states 09:00 or a lesser time, then don't bother or return value 0 (so won't effect calculations.

  16. #16
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Trouble with an IF statement

    So then use Bob's formula, in the sample you attached.....

    =IF(J3<=--"09:00",0,J3-"09:00")

  17. #17
    Forum Contributor
    Join Date
    05-24-2010
    Location
    London England
    MS-Off Ver
    Excel 2003
    Posts
    345

    Re: Trouble with an IF statement

    Quote Originally Posted by NBVC View Post
    So then use Bob's formula, in the sample you attached.....

    =IF(J3<=--"09:00",0,J3-"09:00")
    Hi mate, I could be doing something really silly here.

    But I did what you said in my sample, and it doesn't work.

    It is correct if later than 09:00 but otherwise it returns############

    If I don't format as time then it doesn't work either-and this is with Bob's fomrula on the sample

  18. #18
    Forum Contributor
    Join Date
    05-24-2010
    Location
    London England
    MS-Off Ver
    Excel 2003
    Posts
    345

    Re: Trouble with an IF statement

    Here is the result I get
    Attached Files Attached Files

  19. #19
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Trouble with an IF statement

    Try this slight revision

    =IF(--J3<=--"09:00",0,J3-"09:00")

  20. #20
    Forum Contributor
    Join Date
    05-24-2010
    Location
    London England
    MS-Off Ver
    Excel 2003
    Posts
    345

    Re: Trouble with an IF statement

    Ah did text to col, for J and now it works, it was the other formula that I tried earlier not this one!!!!!

    Thank you everyone for your time.

  21. #21
    Forum Contributor
    Join Date
    05-24-2010
    Location
    London England
    MS-Off Ver
    Excel 2003
    Posts
    345

    Re: Trouble with an IF statement

    Out of interest what does the -- part do before "09:00"?

  22. #22
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Trouble with an IF statement

    Coerces the text formatted number to an actual number....

+ 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