0

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.

chris neilsen
  • 52,446
  • 10
  • 84
  • 123

1 Answers1

0

Try this

Private Sub CommandButton1_Click()
    If RefEdit1.Text = "" Then
        Unload Me
    Else
        MsgBox "Do your Thing"
    End If
End Sub
chris neilsen
  • 52,446
  • 10
  • 84
  • 123