Question

I only have a RefEdit control and a command button on a userform.

enter image description here

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.

Was it helpful?

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
scroll top