Exit a userform if user choose not to input anything
-
22-12-2019 - |
Question
I only have a RefEdit control and a command button on a userform.
This is the desired scenario:
[ If the user after activating the userform, decided not to select any cell range and he just press enter, the userform should just close. ]
What is the code to accomplish the above which I can put into the Private Sub CommandButton1_Click()?
Thank you.
Additional note: I know the user can just click the big red X at the top right corner of the userform to close it. In my case, the user does not want to use the mouse. He is a very keyboard-centric Excel user.
Solution
Try this
Private Sub CommandButton1_Click()
If RefEdit1.Text = "" Then
Unload Me
Else
MsgBox "Do your Thing"
End If
End Sub
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow