Found some tips here and in google, but can't implement properly.
Say I have a loop that runs, and I need to show a box with a button "Cancel". The code must run till I press the button. In the following example I used For Loop and show iteration number in the Label1.Caption
' action of UserForm1 on Button Click
Private Sub CommandButton1_Click()
cancel = True
End Sub
Public cancel as boolean
Sub example ()
cancel = False
Dim i As Integer
For i = 1 To 1000
Application.Wait (Now + #12:00:01 AM#)
UserForm1.Label1.Caption = CStr(i)
UserForm1.Show vbModeless
If cancel = True Then
Exit For
End If
Next i
End Sub
This code runs, but it doesn't react on Button click. If I do UserForm1.Show vbModal, then the code stops and waits till I click the button. What am I doin wrong?