+ Reply to Thread
Results 1 to 9 of 9

Problem With Noon/Midnight

  1. #1
    Registered User
    Join Date
    07-12-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    67

    Problem With Noon/Midnight

    So, in Cell F55, I have a start time and in J55 I have an end time.

    F55 = 12:00:00 PM and J55 = 3:00:00 PM. I'm working on a macro that prints all the hours between the two in the immediate window, but I was getting something weird, it was printing from 1:00 AM until 3:00 PM, so I put "?timevalue(Range("F55").Value)" in the immediate window just to see what Excel thinks "12:00:00 PM" means and I got this:


    Please Login or Register  to view this content.
    Weird, huh? So to see what the value of "12:00 PM" as a double is, I got this:

    Please Login or Register  to view this content.
    And then, when I wanted to know what the time value of "0.5" is:

    Please Login or Register  to view this content.
    So, if I have 12:00 PM as the value of a cell, both of these come up with the same answer, and are both wrong:

    Please Login or Register  to view this content.

    To sum it up, Excel thinks 12:00 PM is 12:05 AM and it's killing me.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    36,773

    Re: Problem With Noon/Midnight

    No mystery. A time is a number expressing a fractional part of a day. Hence 12:00 mid day, 12:00:00 PM, is half way through the day and is represented, as a number, by 0.5.

    Please Login or Register  to view this content.

    Regards, TMS

  3. #3
    Registered User
    Join Date
    07-12-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    67

    Re: Problem With Noon/Midnight

    My problem is that timevalue(Range("F55").Value) comes out as 12:05:00 AM, so

    Please Login or Register  to view this content.
    prints as

    Please Login or Register  to view this content.
    INSTEAD OF

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    07-12-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    67

    Re: Problem With Noon/Midnight

    Oh, nevermind, I just changed "Value" to "text" and it worked. Thanks!

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    36,773

    Re: Problem With Noon/Midnight

    Oh, OK ... did I not suggest that in post #2?


    Regards, TMS


    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  6. #6
    Registered User
    Join Date
    07-12-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    67

    Re: Problem With Noon/Midnight

    You did, I just misunderstood.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    36,773

    Re: Problem With Noon/Midnight

    You're welcome. Thanks for the rep.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    36,773

    Re: Problem With Noon/Midnight

    Looking at this again, TimeValue takes a text string that represents, or looks like, a time and converts it to a numeric value representing a fraction of a day. In this case, you actually have a true numeric time value in the cell ... at least, something that looks to me as something that Excel would interpret as a time.

    Regards, TMS

  9. #9
    Registered User
    Join Date
    05-31-2018
    Location
    Kennett Square, PA, US
    MS-Off Ver
    2016
    Posts
    1

    Re: Problem With Noon/Midnight

    Try converting the fraction value to a double before the conversion to time:
    timevalue(Cdbl(Range("F55").Value))

+ 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. Problem with midnight date change using VBA macro for adding missing dates
    By ABoon86 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-11-2012, 10:20 AM
  2. Replies: 3
    Last Post: 07-26-2012, 10:50 AM
  3. [SOLVED] time sheet problem at midnight!
    By dimiku in forum Excel General
    Replies: 2
    Last Post: 06-19-2012, 06:01 PM
  4. (VBA) Problem with subtracting time values past midnight
    By exEExe in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-31-2012, 12:58 PM
  5. Problem with chart when time spans midnight
    By Relativity in forum Excel General
    Replies: 1
    Last Post: 08-05-2010, 06:21 AM
  6. Add day after midnight
    By ajitexcel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-12-2010, 02:15 AM
  7. Help with Midnight
    By MarcLiq in forum Excel General
    Replies: 1
    Last Post: 10-01-2009, 12:03 PM
  8. NOON for 12:00 PM
    By HuskerBronco in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 12-15-2008, 08:30 AM

Tags for this Thread

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