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 do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Von Pookie

MrExcel MVP
Joined
Feb 17, 2002
Messages
13,686
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
 

sebhughes

New Member
Joined
Sep 21, 2006
Messages
20
Also if they press cancel I want it to make it reappear, how cna I do this. Thansk BTW
 

Von Pookie

MrExcel MVP
Joined
Feb 17, 2002
Messages
13,686
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?
 

sebhughes

New Member
Joined
Sep 21, 2006
Messages
20
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.
 

Von Pookie

MrExcel MVP
Joined
Feb 17, 2002
Messages
13,686
One idea: Don't bother having the user enter a name and just automatically use the username listed in Excel: Application.UserName
 

Forum statistics

Threads
1,141,096
Messages
5,704,312
Members
421,338
Latest member
Pepess

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
Top