+ Reply to Thread
Results 1 to 4 of 4

Formatting timer display in MsgBox

  1. #1
    Registered User
    Join Date
    07-25-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    88

    Formatting timer display in MsgBox

    Hi all. I have a routine that I run daily, and when finished, it displays a message box announcing its completion and the time taken. However, when the MsgBox comes up, the time is in seconds, and usually out to 7+ decimal places. How can I format the timer to display either mm:ss or just seconds, but without any decimals?

    My shortened code is below, leaving out the unrelated stuff in the middle. I thought the formatting I placed in there would do the trick, but it doesn't seem to. Can anyone assist? As always, help is much appreciated. Thanks for reading.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    05-01-2014
    Location
    California, US
    MS-Off Ver
    Excel 2010
    Posts
    1,795

    Re: Formatting timer display in MsgBox

    [.... deleted ....]
    Last edited by joeu2004; 03-04-2015 at 08:39 PM. Reason: resubmitted

  3. #3
    Forum Expert
    Join Date
    05-01-2014
    Location
    California, US
    MS-Off Ver
    Excel 2010
    Posts
    1,795

    Re: Formatting timer display in MsgBox

    Sorry for the incessant posting. Too many corrections and too late to simply edit.
    Quote Originally Posted by Student1990 View Post
    How can I format the timer to display either mm:ss or just seconds, but without any decimals?
    [....]
    Please Login or Register  to view this content.
    First, Timer returns seconds since midnight. So "Duration" might be a misleading variable name as you have used it.

    Second, the two uses of Duration are inconsistent. I suspect the first use should be Format(Timer - Duration,...), like the second use.

    To format as "mm:ss", use:

    Format((Timer - Duration)/86400, "mm:ss")

    because "mm:ss" expects a value that is Excel time, which is a fraction of a day (86400 seconds).

    To format as seconds, use:

    WorksheetFunction.Round(Duration,0)

    I prefer not to use VBA Round because it rounds differently than Excel ROUND.

    PS.... The string Format(..., "[m]:ss") & " seconds." [sic] seems misleading. "12:34 seconds" is incorrect because your format is 12 minutes 34 seconds.

  4. #4
    Registered User
    Join Date
    07-25-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: Formatting timer display in MsgBox

    Thank you - that solves the problem. I really didn't understand Timer and that its seconds since midnight - this is really the key concept here. Much appreciated, Joeu2004.

    -Student1990

+ 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] MsgBox with Timer
    By CarlosAntenna in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-16-2020, 11:18 PM
  2. [SOLVED] Display inactivity timer in text box on userform
    By Klemmdog in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-13-2014, 05:53 PM
  3. Display an Countdown timer on sheet
    By siddisi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-18-2012, 08:57 AM
  4. Get VBA TImer to appear in MsgBox
    By excelhelp711 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-16-2012, 02:05 AM
  5. VBA pop up countdown timer - like a msgbox
    By WAW in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-26-2010, 06:19 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