In order to keep the users on the straight and narrow
Good luck with that
This is close to what you were asking I think
Option Explicit
Sub ValidateAll()
Dim i As Long
'the userform must be loaded first
Load UserForm1
Load UserForm2
Load UserForm3
'goes from 0 to Count-1
For i = 0 To UserForms.Count - 1
With UserForms(i)
Select Case .Caption
Case "UserForm1", "UserForm3"
If Len(.TextBox1.Text) = 0 Then
MsgBox "Enter something in TextBox on " & .Caption
End If
Case "UserForm2"
MsgBox "Testbox can be empty on " & .Caption
End Select
End With
Next i
End Sub
However, if it were me, I'd have a smart (that's the 'ValidateFlags' part) Validated function (second macro), but call it when the user tried to each userform
If ValidatedBeforeLeaving (Me, 1) Then
Me.Hide
Unload me
Endif
Function ValidatedBeforeLeaving(UF As MSForms.UserForm, ValidateFlags As Long) As Boolean
ValidatedBeforeLeaving = False
With UF
Select Case ValidateFlags
Case 1
If Len(.TextBox1.Text) = 0 Then
MsgBox "Enter something in TextBox1 on " & .Caption
Exit Function
End If
If Len(.TextBox2.Text) = 0 Then
MsgBox "Enter something in TextBox2 on " & .Caption
Exit Function
End If
If Len(.TextBox3.Text) = 0 Then
MsgBox "Enter something in TextBox3 on " & .Caption
Exit Function
End If
Case 2
If Len(.TextBox3.Text) = 0 Then
MsgBox "Enter something in TextBox3 on " & .Caption
Exit Function
End If
End Select
End With
ValidatedBeforeLeaving = True
End Function