'Using userform vbmodeless in a loop
I refer to this: How to have VBA code wait until vbModeless userform is closed
I tried to apply the code in a class module for my problem.
Problem description:
I have a userform to insert data, mostly fill text in textboxes.
This userform is opened if incorrect data are found in an Excel table.
I run through the rows of the sheet with a For loop.
When it finds incorrect data it opens the userform to input data manually to textboxes.
With Save and Exit (unload me). I save the data to the sheet.
The reason I use the userform vbmodeless is that I want to copy data from another Excel sheet.
This is not possible if I open the userform vbmodal.
Here is an example of the code:
Option Explicit
Public done As Boolean 'Userform UF_Input filled
Sub Userform_vbmodeless_in_Loop()
'Testprogram with userform vbmodeless in a loop
Dim i As Integer
For i = 1 To 4
UF_Input.TextBox1.Text = "That is the " & i & ". Test"
done = False 'per default
'Loop as long as the input userform is not left
Do While done = False
UF_Event.Show vbModeless
DoEvents
UF_Event.Label1.Caption = "Loop: " & i
Loop
'Unload Event userform
Unload UF_Event
Next i
End Sub
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|