Excel VBA MsgBox basics.

MsgBox Function

Displays a message in a dialog box, waits for the user to click a button, and returns an Integer indicating which button the user clicked.

Syntax

contextDescription
prompta (Must) string, The maximum length of prompt is approximately 1024 characters, If prompt consists of more than one line, you can separate the lines using a carriage return character (Chr(13)
buttonsOptional, the sum of values specifying the number and type of buttons to display, the default value for buttons is 0.
titleOptional. String expression displayed in the title bar of the dialog box.
helpfileOptional. String expression that identifies the Help file to use to provide context-sensitive Help for the dialog box.
contextOptional. Numeric expression that is the Help context number assigned to the appropriate Help topic by the Help author.

Examples

Return Values

ConstantValueDescription
vbOK1OK
vbCancel2Cancel
vbAbort3Abort
vbRetry4Retry
vbIgnore5Ignore
vbYes6Yes
vbNo7No

Example

in this example if you choose "Yes" then the active cell will be erased.

Leave A Comment