+ Reply to Thread
Results 1 to 9 of 9

Difference between initial time and final time code not working correcly!

  1. #1
    Forum Contributor
    Join Date
    05-02-2013
    Location
    Indiana
    MS-Off Ver
    Excel 2016
    Posts
    190

    Difference between initial time and final time code not working correcly!

    I am writing VBA code to calculate the difference between initial time and final time. It works until the time span moves to 13 hours. My application is to calculate the difference between two times. I will never have a value that goes over 24hrs. It works when I give it the following values: Initial 6hr, 30min, AM, Final 11hr, 30min, AM. - I get the value 5hr 0min -correct! The following values do not work: Initial 6hr, 30min, AM, Final 7hr, 30min, FM - I should get 13hr, 0min; however it gives me 1hr, 0min -incorrect!
    Anybody have any idea why it is not calculating correctly? Thanks
    redsab
    Attached Files Attached Files

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

    Re: Difference between initial time and final time code not working correcly!

    Try this:
    Please Login or Register  to view this content.
    _________________
    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!)

  3. #3
    Forum Contributor
    Join Date
    05-02-2013
    Location
    Indiana
    MS-Off Ver
    Excel 2016
    Posts
    190

    Re: Difference between initial time and final time code not working correcly!

    Thanks JBeaucaire,

    That works great! Sometimes I wonder if I can be a programmer when I see some of the coding on this web site! I have not totally figured out your coding, but I will study it. My next phase, is to return a result of 23 hours when I have the following input Initial hour 6:00AM all the way back around to Final hour 5:00AM, which should yield 23 hours. I will see if I can incorporate some of your fancy footwork in my coding!! Thank you very much!
    redsab

  4. #4
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: Difference between initial time and final time code not working correcly!

    Short version, works till 23:59

    Please Login or Register  to view this content.
    Kind regards
    Leo

  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: Difference between initial time and final time code not working correcly!

    Change this line:

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    05-02-2013
    Location
    Indiana
    MS-Off Ver
    Excel 2016
    Posts
    190

    Re: Difference between initial time and final time code not working correcly!

    LeoTaxi,

    That works great! Small little program. I'm still trying to understand it! Thank you.
    redsab

  7. #7
    Forum Contributor
    Join Date
    05-02-2013
    Location
    Indiana
    MS-Off Ver
    Excel 2016
    Posts
    190

    Re: Difference between initial time and final time code not working correcly!

    JBeaucaire, what hat do you pull these formulas from. My attempt at it was a lot more coding, so I'm not going to reinvent the wheel! So if
    Please Login or Register  to view this content.
    evaluates TRUE then you subtract a 1? What does that do?
    Thanks,
    redsab

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

    Re: Difference between initial time and final time code not working correcly!

    Actually the - converts the TRUE/FALSE to 1/0, and that gets added. So whatever the finaltime is it is a fraction of 1, and 1 may be added to that value if FInalitime is less than EndingTime, which 1 equals a day.

  9. #9
    Forum Contributor
    Join Date
    05-02-2013
    Location
    Indiana
    MS-Off Ver
    Excel 2016
    Posts
    190

    Re: Difference between initial time and final time code not working correcly!

    Thanks JBeaucaire, that is clever!
    redsab

+ 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. Calculate time difference based on working hours
    By stanlyj in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-31-2017, 08:39 AM
  2. Find time difference (working hours) on first SwipeIn and last SwipeOut
    By sabha in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-29-2015, 03:32 AM
  3. [SOLVED] Formula for working out top X of a date time difference
    By amasson in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-25-2014, 04:04 AM
  4. Replies: 1
    Last Post: 09-13-2012, 05:50 AM
  5. Replies: 0
    Last Post: 09-13-2012, 05:28 AM
  6. Time Difference Still Not Working
    By bwhizz in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-10-2007, 03:14 PM
  7. Calculating Time difference not working
    By Mindtrap in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-10-2007, 11:17 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