+ Reply to Thread
Results 1 to 5 of 5

Time Stop while SubRoutine executing

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-17-2013
    Location
    Qatar
    MS-Off Ver
    Excel 2010
    Posts
    187

    Time Stop while SubRoutine executing

    Hi,

    How to make the Time will be showing continuously updating while other subroutine is running?
    I have problem the Time is stop while the subroutine is executing.
    Thank you in advance for your helps.
    File as reff.

    Iqballhud
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    09-18-2023
    Location
    Geogia, USA
    MS-Off Ver
    365
    Posts
    309

    Re: Time Stop while SubRoutine executing

    This seems to work well enough:

    Dim showTime As Boolean  ' whether or not the timeloop should run
    
    Private Sub btnCopyCells_Click()
        
        ' copy some cell data - like normal
        Dim rowIndex As Long
        
        For rowIndex = 7 To 16
            Sheet1.Cells(rowIndex, 5).Value = Sheet1.Cells(rowIndex, 3).Value
            DoEvents ' include this in your other subroutine to allow the clock to run
        Next rowIndex
        
    End Sub
    
    Private Sub btnStart_Click()
    
        ' begin displaying the current time until the button
        ' is clicked again to stop the time
        Dim s As Single
        Dim theTime As Double
        Dim displayTime As Variant
        
        If btnStart.Caption = "Start Clock" Then
            ' switch the caption on the button so it can be used to stop the time
            btnStart.Caption = "Stop Clock"
            showTime = True
            DoEvents  ' this comment instructs VBA to allow Excel to refresh the display
        Else
            ' stop the clock and switch back to a start button
            btnStart.Caption = "Start Clock"
            showTime = False
            DoEvents
        End If
        
        ' show the current time, using the timer()
        Do Until Not showTime
            s = Timer()
            theTime = s / (86400)
            displayTime = Format(theTime, "hh:mm:ss")
            Sheet1.Cells(1, 1).Value = displayTime
            DoEvents
        Loop
    
    End Sub
    A video of it working https://1drv.ms/v/s!AkG6_LvJpkR7j61W...S5umQ?e=sgnZsy
    Attached Files Attached Files

  3. #3
    Valued Forum Contributor MikeVol's Avatar
    Join Date
    12-30-2020
    Location
    Odessa / Ukraine
    MS-Off Ver
    MSO Prof Plus 2021 x64 (En)
    Posts
    483

    Re: Time Stop while SubRoutine executing

    Hi @iqballud. You only had to add one line in the InitialRunPL1 procedure. I think you'll find your mistake.
    Sub InitialRunPL1()
    
        Dim A           As Integer
        A = 88
    
        Application.StatusBar = True
        Const valIncrement As Double = 0.1
        Const indexCalc As Single = 0
    
        Dim intMax      As Integer
        Dim intIndex    As Integer
        Dim intCalc     As Double
        intMax = 50
    
        For intIndex = 1 To intMax
            DoEvents
            intCalc = intCalc + valIncrement
            UserForm1.Label1 = Time
            UserForm1.Label2 = Round(intCalc, 1)
            UserForm1.Label2 = Format(intCalc, "0.000")
            Sleep A
        Next
    
        Application.StatusBar = False
    End Sub
    It was my pleasure to help you. Good luck.
    NOTE: As the original poster/owner, only you can mark your thread as SOLVED (Thread Tools above Post #1).
    You can say "Thanks" in your thread to everyone who offered to help you.
    You can also reward them by clicking * "Add Reputation" under their username on the left.
    With Regards, MikeVol.

  4. #4
    Forum Contributor
    Join Date
    11-17-2013
    Location
    Qatar
    MS-Off Ver
    Excel 2010
    Posts
    187

    Re: Time Stop while SubRoutine executing

    Hi,

    Thank you so much for "jdelano" & "MikeVol".
    To MikeVol, yes you are right, i didn't added the time on the DoEvents procedure. It's working fine now.
    To jdelano, another way to do coding. I wish I will use this code for another projects.

    Again thank you so much Guys.

    Cheers, Iqballhud

  5. #5
    Valued Forum Contributor
    Join Date
    09-18-2023
    Location
    Geogia, USA
    MS-Off Ver
    365
    Posts
    309

    Re: Time Stop while SubRoutine executing

    You're welcome, I'm glad you got your code working.

+ 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. Stop another code from executing
    By JyothiGrace in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-23-2022, 12:10 PM
  2. [SOLVED] Excel VBA - How to add command to stop executing the macro
    By Madhusoodan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-17-2020, 04:18 AM
  3. Stop timer, Do While Loop from executing.
    By Wijnand1 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-28-2017, 03:24 AM
  4. [SOLVED] Why does a "do until" loop stop the subroutine?
    By GIS2013 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-28-2015, 11:52 AM
  5. Run a subroutine until another finishes, then stop that sub
    By estratosphere in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-11-2014, 11:02 AM
  6. [SOLVED] Executing a subroutine from within a loop
    By Jeff@DE in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-09-2006, 06:10 AM
  7. Breakpoint will not stop Excel subroutine
    By boswald in forum Excel General
    Replies: 2
    Last Post: 08-23-2005, 08:05 PM

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