+ Reply to Thread
Results 1 to 7 of 7

VBA: Add time since last input

  1. #1
    Forum Contributor
    Join Date
    03-14-2005
    Location
    Sweden
    MS-Off Ver
    Office 365
    Posts
    329

    VBA: Add time since last input

    Hello.

    I am making an excel workbook where operators should make input with buttons etc when an event has occured with the machine they´re running.
    I have a solution which enters the time stamp for when they press the button but I'd like the function to also add the time since last input in another column.
    The thing is that I have several operators who work on different machines so the time must be counted based on which operators(machine) which had an event.

    The function I look for should look in column D if the machine already have inputs earlier the current day. If it finds an input the code should count the time difference between now and the last input. If it doesn't find any earlier data it should enter 00:00:00.
    I have attached a small example how the sheet looks like where the data is stored today.
    I need some support on how to do the coding to make this work.

    Anyone who can help with this tricky question.

    Kind regards
    Anders
    Attached Files Attached Files

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: VBA: Add time since last input

    The example you give ignores the fact that rows 3 & 7 have different dates. Your suggested answer only gives the difference in the minutes and ignores the date altogether.

    Please clarify
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Contributor
    Join Date
    03-14-2005
    Location
    Sweden
    MS-Off Ver
    Office 365
    Posts
    329

    Re: VBA: Add time since last input

    Hello.

    I realize it is a bit harder since the dates can be different. Is it possible to measure time difference and also take the date into account?

    Count number of days x 24 hours..... 48:03:05
    Is it possible?
    Last edited by a94andwi; 11-27-2020 at 09:36 AM.

  4. #4
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: VBA: Add time since last input

    Here is a solution that will compare times and produce a custom time difference of "Days hh:mm:ss" in Column E.

    Please Login or Register  to view this content.
    Last edited by maniacb; 11-28-2020 at 04:56 PM. Reason: Need to tweak further

  5. #5
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: VBA: Add time since last input

    Here is a full solution. It includes the custom time difference function.


    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    03-14-2005
    Location
    Sweden
    MS-Off Ver
    Office 365
    Posts
    329

    Re: VBA: Add time since last input

    Perfect!! I am able to understand how you hade done it and can alter it to fitt the exact function I need.
    After the script have run, I'd like to sort based on column A and b. I have copied your code:

    Please Login or Register  to view this content.
    How to I alter the sort to sort by date and then time for input? (Column A and B)

  7. #7
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: VBA: Add time since last input

    Here is the main function with the updated sort

    Please Login or Register  to view this content.

+ 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. Replies: 1
    Last Post: 06-14-2018, 02:48 PM
  2. [SOLVED] Weighted Average of Sequential Time Based Data Series Using Start/End Time Input
    By marcoyul in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-16-2017, 12:10 PM
  3. [SOLVED] TIME ISN'T ON MY SIDE: Control Time input in HH:MM:SS
    By cmore in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-21-2016, 02:58 AM
  4. Input: Time Zone. Output: Current Time
    By imsteve123 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-09-2015, 09:16 PM
  5. [SOLVED] input date column A, increment B, select blank cell in D and input time. in a macro
    By jeffstu in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-19-2012, 11:19 AM
  6. Date & time auto generated based on input date & time
    By BlastRanger in forum Excel General
    Replies: 18
    Last Post: 09-08-2010, 03:54 AM
  7. Replies: 4
    Last Post: 01-11-2005, 11:06 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