Results 1 to 10 of 10

Thread: Solved: subtract time

  1. #1
    VBAX Tutor
    Joined
    Mar 2005
    Posts
    221
    Location

    Solved: subtract time

    23:25
    0:01

    is there any way to subtract 0:01 (12:01 am) from 23:25 and get :36?

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,476
    Location
    Enter 24:01 instead of 0:01
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Hi, Debauch!

    I?m not clear about what you are trying to accomplish, but let me emphasize that when doing arithmetic with time on two different days, then you must account for the date change too. Also, when subtracting times, then often you need to use brackets in the cell format to enclose the hours value. Instead of using ?hh:mm:ss?, use ?[hh]:mm:ss?.

    Look at this example:

    In cell A1: 6/15/06 23:25
    In cell A2: 6/16/06 00:01
    Format cell A3 as [hh]:mm
    then in A3 put the formula = A2 ? A1
    The result in A3 should be 0:36:00

    HTH
    SId

  4. #4
    VBAX Tutor
    Joined
    Mar 2005
    Posts
    221
    Location
    Thanks both of you for the reply.

    I tried the [ ] formatting on the dates and could not seem to get it working.
    For the most part, the subtraction works fine, until I cross over midnight. I have attached a sample, and you can see the errors, where I am having trouble.

    I have also highlighted the times that are causing the issue. I tried some simple if statements, but they seem to keep reversing what I want it to do.

    (p.s - a few columns look the same, its just different variationsa of what I was trying to do).

  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,476
    Location
    Things are much clearer with samples. As you already have the Range Names, try
    =IF(Logout>Login,Logout-Login,(Logout+24)-Login)
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  6. #6
    VBAX Tutor
    Joined
    Mar 2005
    Posts
    221
    Location
    Genious ... I think I was on the right track ... and you nailed it right on the money. Thanks. Solved.

    P.S - sorry for no attachment the first go 'round.

  7. #7
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,476
    Location
    Like my new signature?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  8. #8
    VBAX Tutor
    Joined
    Mar 2005
    Posts
    221
    Location
    Perfect.

  9. #9
    VBAX Tutor
    Joined
    Mar 2005
    Posts
    221
    Location
    Actually ... Quick question ... where do you find the named ranges? I cannot find theM? Does it just grab the top row reference?

  10. #10
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,476
    Location
    You're absolutely right! I was misreading when I highlighted columns D and D. There must be an "automatic" naming system which I never new about.
    Serendipity!!!
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •