Msgbox if Inputbox entry contains character

S

Steph

Hello. I have an app.inputbox piece of code below. I would like prevent
users from using an underscore ( _ ) in the input box. How can I modify the
code below? Thank you!

userinput = Application.InputBox("User Input")
If userinput = False Then
Exit Sub
Else
***if userinput contains an underscore then
msgbox ("cannot use underscores") vbokonly, then bring
them back to the input box for re-entry
else
Run the rest of my code
 
B

Bob Phillips

Hi Steph,

Her you are

Do
userinput = Application.InputBox("User Input")
Loop Until userinput = False Or InStr(1, userinput, "_") = 0

If userinput = False Then
Exit Sub
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top