View Full Version : Input Box and Msg box Help

10-20-2016, 08:11 AM
Hi All,
I am trying to write a macro that involves and inputbox and msgbox. Here is what I am trying to do:

1. Inputbox to ask user to enter initials (Would like this to be a 2 character alpha only) with the OK/Cancel buttons option

----- a. If the user selects CANCEL then EXIT SUB

2. If the user selects OK and

------ a. the criteria (2 character alpha) OR
------ b. input is blank, Then

---------- I. Msgbox with message “you must enter a valid 2 character initial” with the retry/cancel buttons option

With the msgbox present:

3. If user selects CANCEL then EXIT SUB

4. If user selects RETRY, loop back to step 1 above until,
----- a. User inputs valid initials Or
----- b. User selects the Cancel button option

5. If/when the user enters a valid initial, I would like to jump to a section of the code and run the remainder of the macro.

As long as the user selects RETRY, it will continue to loop starting at STEP 1 above.

Below is the code I have so far. I don't think that I am even close. Any help would be appreciated.


Dim Initials As String
Dim IR As VbMsgBoxResult
Dim MB As VbMsgBoxResult


Initials = InputBox("Please Enter Your Initials for Sign Off", "Enter initials", vbOKCancel)
If Initials = vbCancel Then GoTo ExitAll

ElseIf GoTo Proceed

If Len(Initials) = 0 Then
MsgBox "YOU MUST ENTER A VALID 2 CHARACTER INITIAL", vbRetryCancel, "Invalid Initials"

If vbRetry = 4 Then GoTo retry
If vbCancel = 2 Then


Exit Sub

End If

End If



End Sub

10-20-2016, 12:48 PM
I usually do something like this

Option Explicit

Sub demo()
Dim sInitials As Variant
Dim bGoodInput As Boolean

bGoodInput = False

Do While Not bGoodInput

sInitials = Application.InputBox("Enter TWO initials !!!", "Demo", vbNullString, , , , , 2)
If sInitials = False Then Exit Sub
If Len(sInitials) <> 2 Then
If MsgBox("You must enter a valid 2 character initial", vbCritical + vbRetryCancel, "Demo") = vbCancel Then Exit Sub
bGoodInput = True
End If

MsgBox "run the rest"

End Sub