mlo356
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.
Thanks!
Dim Initials As String
Dim IR As VbMsgBoxResult
Dim MB As VbMsgBoxResult
Retry:
Initials = InputBox("Please Enter Your Initials for Sign Off", "Enter initials", vbOKCancel)
If Initials = vbCancel Then GoTo ExitAll
ElseIf GoTo Proceed
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
ExitAll:
Exit Sub
End If
End If
MainCode:
MY MACRO BELOW
End Sub
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.
Thanks!
Dim Initials As String
Dim IR As VbMsgBoxResult
Dim MB As VbMsgBoxResult
Retry:
Initials = InputBox("Please Enter Your Initials for Sign Off", "Enter initials", vbOKCancel)
If Initials = vbCancel Then GoTo ExitAll
ElseIf GoTo Proceed
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
ExitAll:
Exit Sub
End If
End If
MainCode:
MY MACRO BELOW
End Sub