Userform problem

Roccafelie

Board Regular
Joined
Jun 30, 2008
Messages
129
Hello Everyone

I am looking for a macro or code that if a field not filled or choosen in userform, there will be a error message says "cant continue, please make sure all fields are filled etc..)

I believe it s asked before, but I cant find the relevant thread.

I ll be hapy, if you could give me a hand with that

Thanks
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Example:

Code:
Private Sub CommandButton1_Click()
    If TextBox1.Text = "" Then
        MsgBox "Please complete TextBox1"
        TextBox1.SetFocus
    Else
'       Code if all OK
    End If
End Sub
 
Upvote 0
Private Sub CommandButton1_Click()
If TextBox1.Text = "" Then
MsgBox "Please complete TextBox1"
TextBox1.SetFocus
Else
' Code if all OK
End If
End Sub


but this is only for textbox1 ot filled, what if there are more than 1 text boxes, will it be like this ?

Private Sub CommandButton1_Click()
If TextBox1.Text = "" Then
MsgBox "Please complete TextBox1"
TextBox1.SetFocus
If TextBox2.text = "" Then
MsgBox "Please complete TextBox2"
TextBox1.SetFocus
Else
' Code if all OK
End If
End Sub

?
 
Upvote 0
Like this:

Code:
Private Sub CommandButton1_Click()
    If TextBox1.Text = "" Then
        MsgBox "Please complete TextBox1"
        TextBox1.SetFocus
    ElseIf TextBox2.Text = "" Then
        MsgBox "Please complete TextBox2"
        TextBox2.SetFocus
    Else
'       Code if all OK
    End If
End Sub
 
Upvote 0
If an OptionButton is not checked its value is False. Example:

Code:
Private Sub CommandButton1_Click()
    If OptionButton1.Value = False Then
        If OptionButton2.Value = False Then
            If OptionButton3.Value = False Then
                MsgBox "Please choose an option"
                Exit Sub
            End If
        End If
    End If
'   Code if one OptionButton checked
End Sub
 
Upvote 0
maybe writing a new macro considering their Groupname
e.g if none of the option buttons belongs to Group1 are not chosen then MsgBox "Please choose an option"
 
Upvote 0

Forum statistics

Threads
1,214,648
Messages
6,120,726
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top