+ Reply to Thread
Results 1 to 16 of 16

'IF' statement not working with time data

  1. #1
    Forum Contributor
    Join Date
    07-09-2013
    Location
    Dunedin, New Zealand
    MS-Off Ver
    Excel 2016
    Posts
    105

    'IF' statement not working with time data

    Hi

    I have column A - time data e.g. 12:00:00
    Column B - time buckets formula = A2 - MOD(A2, 40/24/60) which creates 40 minute buckets

    Now for two of them, and just two of them, I wish to create 30 minute buckets i.e. using A2-MOD(A2, 30/24/60)

    I have tried something like the following but excel is not happy

    =IF((A2>=12:00:00) AND (A2<12:40:00), A2-MOD(A2, 30/24/60), IF((A2>=16:00:00) AND (A2<16:40:00), A2-MOD(A2, 30/24/60), A2-MOD, 40/24/60))

    Help

    Bob M

    p.s. I am not worried about the odd bits created by shrinking 40 minutes down to 30 minutes
    Last edited by FDibbins; 07-13-2013 at 08:32 PM.

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,946

    Re: Problem with 'IF' statement

    Looks likje you were almost there

    Try this...
    =IF(AND(A2>=12:00:00,A2<12:40:00,A2>=16:00:00,A2<16:40:00), A2-MOD(A2, 30/24/60), A2-MOD(A2, 40/24/60))

    (you had a problem with the AND, not the IF lol)
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Forum Contributor
    Join Date
    07-09-2013
    Location
    Dunedin, New Zealand
    MS-Off Ver
    Excel 2016
    Posts
    105

    Re: Problem with 'IF' statement

    Hi there

    Have tried the above formula but Excel is still unhappy

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,946

    Re: 'IF' statement

    OK do you have a sample for me to look at? Show what you are working with, a few expected answers and how you got them (if needed)

  5. #5
    Forum Contributor
    Join Date
    07-09-2013
    Location
    Dunedin, New Zealand
    MS-Off Ver
    Excel 2016
    Posts
    105

    Re: 'IF' statement

    Hi again

    what is wrong with the current suggested formula is that the AND is being used for the two different time buckets

    we need an OR between the 12:00 to 12:40 period and the 16:00 to 16:40 period

    does this make sense?

    Bob M

  6. #6
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,946

    Re: 'IF' statement not working

    OK Im just guessing now, although the way I put the AND() together, it should work for both time frames

    =IF(or(AND(A2>=12:00:00,A2<12:40:00),and(A2>=16:00:00,A2<16:40:00)), A2-MOD(A2, 30/24/60), A2-MOD(A2, 40/24/60))

    If that doesnt work, upload a sample workbook

  7. #7
    Forum Contributor
    Join Date
    07-09-2013
    Location
    Dunedin, New Zealand
    MS-Off Ver
    Excel 2016
    Posts
    105

    Re: 'IF' statement not working

    The above looks OK to me but still Excel is not happy

    you need the OR !

    here is some data

    12:29:58.306 12:30:00
    12:29:58.406 12:30:00
    12:29:58.407 12:30:00
    12:29:58.758 12:30:00
    12:30:01.606 12:40:00
    12:30:01.708 12:40:00
    12:30:01.709 12:40:00
    12:30:01.710 12:40:00

    Bob M

  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: 'IF' statement not working

    the time needs to be in quotes
    =IF(OR(AND(A10>="12:00:00",A10<"12:40:00"),AND(A10>="16:00:00",A10<"16:40:00")),A10-MOD(A10, 30/24/60), A10-MOD(A10, 40/24/60))
    "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

  9. #9
    Forum Contributor
    Join Date
    07-09-2013
    Location
    Dunedin, New Zealand
    MS-Off Ver
    Excel 2016
    Posts
    105

    Re: 'IF' statement not working

    Thank you

    Exactly what I wanted

    Bob M

  10. #10
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,946

    Re: 'IF' statement not working

    Thanks for the assist Martin
    Last edited by FDibbins; 07-14-2013 at 07:22 PM. Reason: removed unnecessary text

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

    Re: 'IF' statement not working

    hm it had problems but this is better
    =IF(OR(AND(A2>=VALUE("12:00:00"),B2<VALUE("12:40:00")),AND(A2>=VALUE("16:00:00"),B2<VALUE("16:40:00"))),(A2-MOD(A2, 40/24/60)),(A2-MOD(A2,30/24/60)))

  12. #12
    Forum Contributor
    Join Date
    07-09-2013
    Location
    Dunedin, New Zealand
    MS-Off Ver
    Excel 2016
    Posts
    105

    Re: 'IF' statement not working

    Hi again

    I spoke too soon

    Martin Wilson suggested the following:-

    hm it had problems but this is better
    =IF(OR(AND(A2>=VALUE("12:00:00"),B2<VALUE("12:40:00")),AND(A2>=VALUE("16:00:00"),B2<VALUE("16:40:00"))),(A2-MOD(A2, 40/24/60)),(A2-MOD(A2,30/24/60)))

    The 40 and the 30 need reversing but I have tried this on a full set of data and......................

    The formula is producing 30 minute time buckets at times other than 12:00 - 12:39 and 16:00 thru 16:39

    How odd?

    So still not what I am seeking

    Bob M

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

    Re: 'IF' statement not working with time data

    lets try again with just say 10 time values of showing the results expected for each,in an excel work book
    Attach a sample workbook. Make sure there is just enough data to make it clear what is needed. 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 demonstrated, mock them up manually if needed. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  14. #14
    Forum Contributor
    Join Date
    07-09-2013
    Location
    Dunedin, New Zealand
    MS-Off Ver
    Excel 2016
    Posts
    105

    Re: 'IF' statement not working with time data

    Hi

    I am afraid a sample of a dozen records does not really show the end result

    What I am doing currently:-

    Using the formula =A2-MOD(A2, 40/24/60) for all 1 million records say

    I then manually locate the beginning of my two special periods i.e. 12:00:00 and 16:00:00 for each day and manually change the formula to A2-MOD(A2, 36/24/60)

    When I use the much longer all embracing formula - it does the two special periods correctly BUT also changes other periods - seemingly randomly

    Bob M

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

    Re: 'IF' statement not working with time data

    whet ones dont work then? just post some that do and some that don't from your real data

  16. #16
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,946

    Re: 'IF' statement not working with time data

    You have been asked for a sample file three times already. If you cant/dont want to provide 1, Im not guessing any more.

+ 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. [SOLVED] Use time data from an exported report in a formula - not working!
    By psgolfer32381 in forum Excel General
    Replies: 5
    Last Post: 12-19-2012, 11:14 AM
  2. [SOLVED] Calculate turnaround time for 9pm-6am working time & Start/End date may be on weekend
    By Wauiwa in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 10-26-2012, 02:36 PM
  3. Working While Statement Stops Working
    By Verbaruab in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-10-2011, 05:58 PM
  4. [SOLVED] Using an IF statement on time based data
    By DonB in forum Excel General
    Replies: 11
    Last Post: 12-03-2005, 12:10 AM
  5. problem working with time data imported from text file
    By afaqm in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-24-2005, 04:06 AM

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