Search code examples
vbaexcelexcel-2007

Pausing a module, until user clicks submit to continue running the module


I'm creating a user interface whereby the user clicks the "click to select" button on the worksheet and it call and run Module 1 to a certain point, stores the information, pause the module. Module 1 should only continue running after user clicks the submit button on the worksheet.


UPDATE!!

its not only 1 Module. its actually 6 modules. In which, the submit button has to continue, where it paused/stopped. its there anyway that I could link the submit button to 6 different modules?

enter image description here

Sub FlowRate()

    Set chwflow_rate1 = Application.InputBox("Please select 1st cell with
    Chilled Water Flowrate.", Type:=8)
    Range(chwflow_rate1, chwflow_rate1.Offset(20159)).Select
    Selection.Copy

  ' Program pause until user clicks submit button
  ' user click submit, program continues
    Workbooks(1).Activate
    Sheets("Data").Activate
    Range("C8").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    ActiveCell.EntireColumn.Offset(0, 1).Insert
    With ActiveSheet
        For I = 7 To Cells(.Rows.Count, "C").End(xlUp).Row
            aSplit = Split(Cells(I, "C"), " ", 8)
            Cells(I, "C") = aSplit(0)
            Cells(I, "D") = aSplit(1)
        Next I
    End With
    Range("D8").Select
    ActiveCell.EntireColumn.Delete 
 End Sub

Solution

  • Split the functionality into two seperate procedures like this, and have the submit button linked to FlowRateSubmit().

    Sub FlowRate()
    
        Set chwflow_rate1 = Application.InputBox("Please select 1st cell with
        Chilled Water Flowrate.", Type:=8)
        Range(chwflow_rate1, chwflow_rate1.Offset(20159)).Select
        Selection.Copy
    End Sub
    
    Sub FlowRateSubmit()
    
      ' Program pause until user clicks submit button
      ' user click submit, program continues
        Workbooks(1).Activate
        Sheets("Data").Activate
        Range("C8").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveCell.EntireColumn.Offset(0, 1).Insert
        With ActiveSheet
            For I = 7 To Cells(.Rows.Count, "C").End(xlUp).Row
                aSplit = Split(Cells(I, "C"), " ", 8)
                Cells(I, "C") = aSplit(0)
                Cells(I, "D") = aSplit(1)
            Next I
        End With
        Range("D8").Select
        ActiveCell.EntireColumn.Delete 
     End Sub