+ 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-24-2021
    Location
    India
    MS-Off Ver
    office 365
    Posts
    3

    UserForm - Two Button - Start and Pause button

    Hi,

    In my project i have user form with three buttons start, pause and resume, start function will perform operation for around 10K data using for loop, and I want 2nd button to pause the function in between 100th or any position and 3rd button resume the same function from where it left. Please help on this I am trying to pause function its not working for me.

    after clicking start button other button are not able to click, after 10K data entry is completed only I can able to click.

    Thanks

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,748

    Re: UserForm - Two Button - Start and Pause button

    Please show all the code in your UserForm module. Use code tags. It would be even better to just attach your Excel file, see yellow banner at the top of the page.

    There are two ways to add code tags. One is to select the code part of the text so it is highlighted, then press the "#" button in the edit controls. The other is to simply type in the tags:

    [code]
    ' your code goes here
    [/code]


    Why use code tags? Code tags:

    1. Are required by rules (see rule #2)
    2. Preserve spacing used to show code structure (otherwise leading spaces and repeated spaces are removed)
    3. Add scroll bars to navigate code with long lines or a lot of lines
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

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

    Re: UserForm - Two Button - Start and Pause button

    please find below the code, I want to pause the bulkData function when click on commandButton2

    Private Sub CommandButton2_Click()
        MsgBox "msg"
    End Sub
    
    Private Sub CommandButton3_Click()
      'Call Add_Dynamic_OptionButton
      Call bulkData
      
    End Sub
    Public Sub bulkData()
        Dim k As Long, j As Long
        Call UserForm1.UserForm_Initialize
        'ActiveWorkbook.Sheets("Sheet3").Activate
        'k = Cells(Sheets("Sheet3").Rows.Count, "C").End(xlUp).row
       k = ActiveWorkbook.Sheets("Sheet3").UsedRange.Rows.Count
       j = Cells(Sheets("Sheet1").Rows.Count, "C").End(xlUp).row - 3
        For i = j To j + 10
            'Sheets("Sheet1").Activate
            Application.Wait (Now + TimeValue("0:00:2"))
            If ActiveWorkbook.Sheets("Sheet3").Range("D" & i).Value = 0 Then
                Sheets("Sheet1").Activate
                Call UserForm1.CommandButton1_Click
            Else
                Sheets("Sheet1").Activate
                Call UserForm1.CommandButton2_Click
                
            End If
            CommandButton2.Enabled = True
        Next i
    End Sub
    
    Private Sub CommandButton1_Click()
        Resume_Macro = True
        MsgBox "msg"
    End Sub
    Last edited by balaji761995; 04-25-2021 at 04:19 AM.

  4. #4
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,309

    Re: UserForm - Two Button - Start and Pause button

    no attachment - paperclip does not work.
    see big yellow banner - how to upload workbook.

  5. #5
    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

  6. #6
    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

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,748

    Re: UserForm - Two Button - Start and Pause button

    If your question has been answered please mark your thread as "Solved" so that members will know by looking at the thread title that your problem is solved. Go to the menu immediately above your first post to the thread and click on Thread Tools. From the dropdown menu select "Mark this thread as solved..."

    If a member helped you solve your problem, consider adding to their reputation by clicking on the star icon addreputationiconsmall.jpg below their name.

+ 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