+ Reply to Thread
Results 1 to 7 of 7

UserForm - Two Button - Start and Pause button

Hybrid View

  1. #1
    Registered User
    Join Date
    04-19-2021
    Location
    Dublin, Ireland
    MS-Off Ver
    O365, Win10 and Mac
    Posts
    47

    Re: UserForm - Two Button - Start and Pause button

    I have restructured the logic a bit. You just need one button which acts as the start and pause / resume. The code for your userform will be as follows:
    It is all contained in the attached workbook.
    Option Explicit
    Dim NextRow As Long
    Dim FirstRow As Long
    Dim PausePressed As Boolean
    Dim nrRows As Long
    
    Private Sub cmdPauseResume_Click()
        If NextRow = 0 Then
            PausePressed = False
            NextRow = FirstRow
            cmdPauseResume.Caption = "Pause"
            Call ImportData
        Else
            PausePressed = Not PausePressed
            cmdPauseResume.Enabled = False
            If Not PausePressed Then
                cmdPauseResume.Caption = "Pause"
                cmdPauseResume.Enabled = True
                Call ImportData
            End If
        End If
    End Sub
    
    Public Sub ImportData()
        
        Do While NextRow <= nrRows
            If PausePressed And NextRow > 1000 And NextRow Mod 100 = 0 Then
                Exit Do
            End If
            '  Your code for importing row NextRow
            NextRow = NextRow + 1
            If NextRow Mod 10 = 0 Then
                lblProgress.Caption = "Processing row " & NextRow & " of " & nrRows
            End If
            DoEvents
        Loop
        If NextRow > nrRows Then
            MsgBox "All done"
        Else
            cmdPauseResume.Caption = "Resume"
            cmdPauseResume.Enabled = True
            MsgBox "You told me to take a rest"
        End If
    End Sub
    
    Private Sub UserForm_Initialize()
        nrRows = 100000  '  Your code for working out how many rows   'ActiveWorkbook.Sheets("Sheet3").UsedRange.Rows.Count
        FirstRow = 1 ' Your code for working out where to start  'Cells(Sheets("Sheet").Rows.Count, "C").End(xlUp).Row - 3
        NextRow = 0
        cmdPauseResume.Caption = "Start"
    End Sub
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    04-24-2021
    Location
    India
    MS-Off Ver
    office 365
    Posts
    3

    Re: UserForm - Two Button - Start and Pause button

    thank you so much for your help

+ 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. running timer in excel with start, pause and end button
    By melody10 in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 09-23-2021, 04:36 AM
  2. Create running stopwatch/timer with 1 button (start/stop). No reset button.
    By leeroy2612 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-26-2021, 12:59 AM
  3. [SOLVED] Start / Pause timer Button
    By N323100 in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 07-26-2017, 10:35 AM
  4. Countdown Timer in Excel with a "pause" and "start" button
    By bbhagwat in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-13-2013, 05:49 AM
  5. Using a worksheet command button to start userform initialize procedures
    By paulary30 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-21-2012, 12:25 PM
  6. Promblem with userform if I don't start by the play button
    By mimoza in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-28-2011, 04:20 PM
  7. Abort button for a macro(not the break key) and pause/resume button
    By c.vaibhav in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-21-2009, 04:22 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