lezawang
Well-known Member
- Joined
- Mar 27, 2016
- Messages
- 1,805
- Office Version
- 2016
- Platform
- Windows
Hi
I have a simple UserForm. It has 2 textboxes (myname, myage) and 2 option buttons (male, female) and 1 control button (enterme) . Please see the code below.
What I want to add is to give a user a message, if the user forget to enter Name, age, and sex and hit Enter button. So I came with the following idea to fix the issue if the user did not enter name
How you would do that? is that good programming style? Thank you.
I have a simple UserForm. It has 2 textboxes (myname, myage) and 2 option buttons (male, female) and 1 control button (enterme) . Please see the code below.
What I want to add is to give a user a message, if the user forget to enter Name, age, and sex and hit Enter button. So I came with the following idea to fix the issue if the user did not enter name
Code:
If myname.Value = "" Then
MsgBox "enter name"
End If
How you would do that? is that good programming style? Thank you.
Code:
Private Sub enterme_Click()
Dim x As Double
x = Cells(Rows.Count, 1).End(xlUp).Row
If myname.Value = "" Then
MsgBox "enter name"
End If
Cells(x + 1, 1).Value = myname.Value
Cells(x + 1, 2).Value = myage.Value
If male.Value = True Then
Cells(x + 1, 3).Value = "male"
ElseIf female.Value = True Then
Cells(x + 1, 3).Value = "female"
End If
End Sub
Last edited: