+ Reply to Thread
Results 1 to 5 of 5

Multiple Timers, Multiple Events

Hybrid View

singinwes Multiple Timers, Multiple... 07-30-2020, 02:38 PM
Greg M Re: Multiple Timers, Multiple... 07-30-2020, 04:44 PM
singinwes Re: Multiple Timers, Multiple... 08-04-2020, 09:16 AM
singinwes Re: Multiple Timers, Multiple... 08-04-2020, 10:40 AM
Greg M Re: Multiple Timers, Multiple... 11-29-2020, 08:32 PM
  1. #1
    Registered User
    Join Date
    07-30-2020
    Location
    Charleston, SC
    MS-Off Ver
    Office 365
    Posts
    30

    Question Multiple Timers, Multiple Events

    I am well experienced in Excel, but am starting my first real VBA project. I have typically found what I've needed in the past and copied and pasted it, but I know that won't be the case for this project. I have researched event handlers and basic countdown timers, but I haven't figured out how to piece this idea together.

    Basically, I need a separate hour long timer in each row that starts when something is entered into that row's column B. With just a basic timer and event handler, I'm able to call a start_timer when something is entered into B:B, but that only works with one row. I have thought of running separate modules per row (start_timerF, start_timerG, etc.) but that would be dozens of modules running and I doubt that's the best way to move forward. I'm not necessarily hoping for a copy paste answer, though that would be incredible. I'm just hoping someone here knows of the right path forward for me to figure this out. I appreciate your time and any help you can provide!
    Last edited by singinwes; 08-17-2020 at 12:10 PM. Reason: Solved

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: Multiple Timers, Multiple Events

    Hi there,

    Take a look at the attached workbook and see if it gets you moving in the right direction. It uses the following code in the VBA CodeModule for the worksheet:

    
    
    
    Option Explicit
    
    
    '=========================================================================================
    '=========================================================================================
    
    
    Const msPROCEDURE_NAME  As String = "UpdateTimers"
    
    
    '=========================================================================================
    '=========================================================================================
    
    
    Private mdteNextTime    As Date
    
    
    '=========================================================================================
    '=========================================================================================
    
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    
        Const sCOLUMN_CHANGE    As String = "B"
        Const sCOLUMN_START     As String = "C"
        Const sCOLUMN_TIMER     As String = "D"
        Const iFIRST_ROW_NO     As Integer = 3
        Const sFORMULA          As String = "=NOW() - INT(NOW()) - RC[-1]"
    
        Dim rTarget             As Range
    
        Set rTarget = Target
    
        If rTarget.Cells.CountLarge = 1 Then
    
            If rTarget.Column = Me.Columns(sCOLUMN_CHANGE).Column And _
               rTarget.Row >= iFIRST_ROW_NO Then
    
                Intersect(rTarget.EntireRow, _
                          Me.Columns(sCOLUMN_START)).Value = Now() - Int(Now())
    
                Intersect(rTarget.EntireRow, _
                          Me.Columns(sCOLUMN_TIMER)).FormulaR1C1 = sFORMULA
    
                Call UpdateTimers
    
            End If
    
        End If
    
    End Sub
    
    
    '=========================================================================================
    '=========================================================================================
    
    
    Private Sub UpdateTimers()
    
        Const iUPDATE_INTERVAL  As Integer = 1  '<<  Interval in seconds between timer updates
    
        Dim dteInterval         As Date
    
        dteInterval = TimeValue("00:00:" & Format(iUPDATE_INTERVAL, "00"))
    
        If mdteNextTime > 0 Then
              mdteNextTime = mdteNextTime + dteInterval
        Else: mdteNextTime = Now() + dteInterval
        End If
    
        Me.Calculate
    
        Application.OnTime EarliestTime:=mdteNextTime, _
                           Procedure:=Me.Name & "." & msPROCEDURE_NAME
    
    End Sub
    
    
    '=========================================================================================
    '=========================================================================================
    
    
    Private Sub StopProcess()
    
        On Error Resume Next
    
            Application.OnTime EarliestTime:=mdteNextTime, _
                               Procedure:=Me.Name & "." & msPROCEDURE_NAME, Schedule:=False
    
            mdteNextTime = 0
    
        On Error GoTo 0
    
    End Sub

    The highlighted values may be altered to suit your requirements, but note that the following line:

    
    Const sFORMULA          As String = "=NOW() - INT(NOW()) - RC[-1]"
    assumes that the "Start" and "Elapsed" columns are adjacent to each other.


    Hope this helps - please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    07-30-2020
    Location
    Charleston, SC
    MS-Off Ver
    Office 365
    Posts
    30

    Re: Multiple Timers, Multiple Events

    This is super helpful and we can make this work swimmingly, thank you! I'm wondering if it's possible to make each line stop when it hits an hour. Everything I have thought of would stop all of them when the first one hits an hour. Any insights into accomplishing this?

  4. #4
    Registered User
    Join Date
    07-30-2020
    Location
    Charleston, SC
    MS-Off Ver
    Office 365
    Posts
    30

    Re: Multiple Timers, Multiple Events

    I changed Const sFORMULATE to "=IF(NOW()-INT(NOW())-RC[-1]<0.04167,NOW()-INT(NOW())-RC[-1],0.04167)" and was able to have each line item stop as an hour. This made our project exactly as we had hoped, thank you for your help!

  5. #5
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: Multiple Timers, Multiple Events

    Hi again,

    Sorry about the delay in replying - other projects got in the way of the forum!

    Many thanks for all of your feedback and also for the recent Reputation increase - much appreciated!

    You're welcome - glad I was able to help.

    Best regards,

    Greg M

+ 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. Excel VBA - Multiple procedures in 1 sheet to set up multiple timers
    By flyerspuck100 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-26-2018, 01:04 PM
  2. multiple timers
    By kadlaw in forum Excel General
    Replies: 2
    Last Post: 11-14-2017, 04:56 AM
  3. Multiple timers
    By OillyBob55 in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 08-17-2017, 04:38 PM
  4. Multiple Countdown timers.
    By dawidski in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-12-2013, 11:42 PM
  5. Multiple Timers within EXcel
    By Janto724 in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 04-26-2013, 09:07 AM
  6. Setup Multiple Timers
    By jomili in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-02-2010, 04:38 PM
  7. Running multiple timers
    By tropy in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-17-2006, 09:44 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