+ Reply to Thread
Results 1 to 9 of 9

How to subtract Time Values contained in Labels on a userform - Time Elapsed Live Clock

  1. #1
    Registered User
    Join Date
    07-17-2017
    Location
    Ireland
    MS-Off Ver
    2016
    Posts
    5

    Angry How to subtract Time Values contained in Labels on a userform - Time Elapsed Live Clock

    Hi All,

    Fairly new to the forum here, although I have been using similar forums for years to help self-learn Excel functionality and recently some VBA.

    I've deduced a good bit to get started here but I feel it is something relatively simple required to just get me over the line with what I want to achieve. Again I've trawled the internet trying to find a simpler way of just "displaying a time elapsed between clicking of each button timer" but this is the closest I've yet to get.

    Basically I have a user form designed for inputting details of calls received by a Helpdesk. One of the things I want to achieve is a running clock of how long the call has lasted.

    To achieve this users must click - a Button (Button1) which will:
    1. record the start time of the call and place in caption of Label14 (not working)
    2. display a running clock in Label 12 based on the "Time" functionality of VBA (working fine-code below)
    3. display the amount of time elapsed so far on the call by simply subtracting 2(above) from 1(above) and placing result in Label13 (not working)
    Users must then click another button (Button2) which will input all the data from the form onto an excel sheet in the background (working)

    Again I am using the code to refresh every second for a live timer in both respects, but if there is a simpler way I've yet to find it.

    If anyone can help me with this it would be greatly appreciated. Code below:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,947

    Re: How to subtract Time Values contained in Labels on a userform - Time Elapsed Live Cloc

    Try this for ' Label 14 = time button clicked (NOT WORKING)
    Please Login or Register  to view this content.
    And for the second (NOT WORKING):

    Please Login or Register  to view this content.
    and for the third (NOT WORKING):

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    07-17-2017
    Location
    Ireland
    MS-Off Ver
    2016
    Posts
    5

    Re: How to subtract Time Values contained in Labels on a userform - Time Elapsed Live Cloc

    Thanks for you help Bernie, however when I run the form and click Button 1 I am now getting the following error:

    "Compile error:
    Method or data member not found"

    With the "Private Sub CommandButton1_Click()" highlighted yellow
    and the ".Value" in "Me.Label13 = Format(TimeValue(Label12.Value) - TimeValue(Start_time.Value), "hh:mm:ss")" highlighted in blue.


    I was getting this error to begin with I think....

    Anybody shed some light?


    Surely with the Clock working it should simply be a matter of setting the OnTime function to take the starting time (i.e. when button was clicked) away from the current clock time value?

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: How to subtract Time Values contained in Labels on a userform - Time Elapsed Live Cloc

    Hi,

    Replace Value with Caption since labels don't have a Value property.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  5. #5
    Registered User
    Join Date
    07-17-2017
    Location
    Ireland
    MS-Off Ver
    2016
    Posts
    5

    Re: How to subtract Time Values contained in Labels on a userform - Time Elapsed Live Cloc

    Hi Folks,

    Code is now as follows:
    User Form Code:
    Please Login or Register  to view this content.
    Module 1 Code:
    Please Login or Register  to view this content.
    Getting an error saying "Object Required" and the bolded line above highlighted in Yellow.

    Are we nearly there do you think? When button clicked the form shows figures in each label box before the error comes up?

  6. #6
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: How to subtract Time Values contained in Labels on a userform - Time Elapsed Live Cloc

    You must specify the form for all the labels thus
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    07-17-2017
    Location
    Ireland
    MS-Off Ver
    2016
    Posts
    5

    Re: How to subtract Time Values contained in Labels on a userform - Time Elapsed Live Cloc

    Ok Guys,

    Code below:

    Please Login or Register  to view this content.
    Module 1 code:
    Please Login or Register  to view this content.
    When commenting out the SUBTRACTION code, bother the timer label 12 and the start time label14 are working fine. Therefore the problem just seems to be in the code for Label 13 i.e. having the code subtract label14 caption from label12 caption every second.

    Any help here would be appreciated.

  8. #8
    Registered User
    Join Date
    07-17-2017
    Location
    Ireland
    MS-Off Ver
    2016
    Posts
    5

    Re: How to subtract Time Values contained in Labels on a userform - Time Elapsed Live Cloc

    Thanks xlnitwit

    Knew it was something simple.

    Its now working, however the elapsed time (label13) only updates every two seconds (this is probably just as a result of my On Time functions clashing.)

    Any ideas how to get it to update every second just like the Label12? Should I stagger them by 0.5 sec or what would be best?


    Thanks again for all your help!

  9. #9
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: How to subtract Time Values contained in Labels on a userform - Time Elapsed Live Cloc

    Why not use the same routine to update both labels?

+ 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] Work out elapsed time with a dynamic clock
    By er101 in forum Excel Formulas & Functions
    Replies: 24
    Last Post: 05-11-2016, 12:37 PM
  2. Have excell play sound when any cell shows same time as live clock
    By boredinyak in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-08-2015, 08:35 PM
  3. Subtract Time to 24h00 clock
    By JPS1 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-20-2014, 08:39 AM
  4. [SOLVED] Can't Stop Live Time / Real Time Clock
    By puuts in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-03-2014, 12:39 PM
  5. [SOLVED] Elapsed time / clock frustration
    By jaycee66 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-11-2013, 03:12 PM
  6. Using start/end time fields on userform to populate elapsed time on spreadsheet
    By Lothar69 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-11-2011, 05:07 PM
  7. Replies: 2
    Last Post: 08-26-2009, 02:56 PM

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