Reputation: 25
I'm having trouble to loop an userform and get data from it. My code is already properly working whenever I use it for a single use (out of the loop). The objective is to send data obtained using the ComboBox values (which is done in the Userform code) in a sheet and this has to be done X times (X being defined by the user at the start of the code) but whenever I enter the loop, my userform is only displayed once. I did see that some people used the vbModeless option but since I didn't notice any change, I thought of it being a hint but didn't find anything close to it that solved my problem.
Sub nouveau_controle()
Dim nbre_controle As Integer
nbre_controle = InputBox("Entrez le nombre de contrôles à effectuer")
For j = 1 To nbre_controle Step 1
Formulaire_nouveau_controle.Show vbModeless
Next j
End Sub
Thank you for any help you can give me.
Upvotes: 0
Views: 374
Reputation: 29146
If you open a form vbModeless
, it means 2 things:
(1) you can continue to work with excel while the form is open
(2) your code will immediately continue to run after the Show
As the code continues to run, your code hits the Show
-command without stop. When the user closes it, it is not reopened as the code is already executed completely
The opposite is to open the form modal
(this is the default). Execution stops at the Show
command and waits until the form is closed. In that case, you should see you form multiple times. Examples for typical modal forms are InputBox
or MsgBox
Upvotes: 1