Input Box Validation

sebhughes

New Member
Joined
Sep 21, 2006
Messages
20
I have an input box that appears when sombody opens the workbook, It asks for there name and if they dont enter anything and press ok, I want it to display the sameinputbox over and over again until they enter a value.

How can I do this?
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
A very simple example, but should (hopefully) give you an idea of one way you could do this:

Code:
Sub test()
Dim strName As String

Do
    strName = Application.InputBox("Enter your name:", Type:=2)
    Select Case strName
        Case Is = False 'cancel button is clicked
            Exit Sub 'end macro
        Case Is = "" 'no value entered
            MsgBox "You must enter a name to continue.", vbOKOnly + vbExclamation
    End Select
'loop and re-display inputbox until a value is entered
Loop Until strName <> ""

MsgBox "You entered: " & strName


End Sub
 
Upvote 0
Er...I really don't recommend doing that. :unsure: I'm not saying it can't be done, it is just a very bad idea, in my opinion.

A 'cancel' button should be used to do just that--cancel the process.

What are you trying to do? The user enters their name and then what? Why do they need to enter a name?
 
Upvote 0
Well I have made a form that send thes data to a user using netsend, and at the end of the message it adds there name so people know who it is. So the name is a must so people know who it is.
 
Upvote 0
One idea: Don't bother having the user enter a name and just automatically use the username listed in Excel: Application.UserName
 
Upvote 0

Forum statistics

Threads
1,214,620
Messages
6,120,559
Members
448,970
Latest member
kennimack

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top