VBA get user input

Dim is used to declare a new variable. The word following Dim is the variables name and can be called later on after the variable value is assigned. As Variant indicates the variable can be any data type, text or a number.

 

Dim myValue As Variant

Dim = Declare new variable

myValue = new variables name

As Variant = Data type can vary, text or number.

myValue = InputBox("Message boxes help text here")
Sub Get_User_Input()
Dim myValue As Variant

myValue = InputBox("User input")
Range("B1").Value = myValue

End Sub

VBA to prompt user to take confirm msgbox question.  Designate what buttons to display in the message box by changing the constant value for example vbYesNo will display Yes button and No button on the user input message box.

Response = MsgBox("Did the Halt Trading emails generate successfully?", vbYesNo, Confirm)

Constant Value Description
vbOKOnly    0 Display OK button only.
vbOKCancel    1 Display OK and Cancel buttons.
vbAbortRetryIgnore    2 Display AbortRetry, and Ignore buttons.
vbYesNoCancel    3 Display YesNo, and Cancel buttons.
vbYesNo    4 Display Yes and No buttons.
vbRetryCancel    5 Display Retry and Cancel buttons.
vbCritical 16 Display Critical Message icon.
vbQuestion 32 Display Warning Query icon.
vbExclamation 48 Display Warning Message icon.
vbInformation 64 Display Information Message icon.
vbDefaultButton1    0 First button is default.
vbDefaultButton2  256 Second button is default.
vbDefaultButton3  512 Third button is default.
vbDefaultButton4  768 Fourth button is default.
vbApplicationModal    0 Application modal. The user must respond to the message box before continuing work in the current application.
vbSystemModal 4096 System modal. On Microsoft Win16 systems, all applications are suspended until the user responds to the message box. On Microsoft Win32 systems, this constant provides an application modal message box that always remains on top of any other programs that you have running
'Get user input

'https://msdn.microsoft.com/en-us/library/sfw6660x(VS.85).aspx

Response = MsgBox("Did the Halt Trading emails generate successfully?", vbYesNo, Confirm)
result = MsgBox("Enter Response",vbYesNoCancel)
Constant Value Button
vbOK 1 OK
vbCancel 2 Cancel
vbAbort 3 Abort
vbRetry 4 Retry
vbIgnore 5 Ignore
vbYes 6 Yes
vbNo 7 No