MsgBox in Excel

MsgBox in Excel

MsgBox is a dialog box in MS Excel VBA that can be used to inform the users related to any information, alert, warning etc. To start with this tutorial, follow the steps below:

1. Place a command button on worksheet

command button

2. Right click CommandButton1 and select view code.

CommandButton1

3. On visual basic screen, under the click event for CommandButton1, type following code:

MsgBox “Welcome to my first Msg Box tutorial”

MsgBox

4. Close the VB screen and click the Command button.

5. Result would look like the image below

Result

In another tutorial, you will observe how to display a value of Cell into a text box. Follow the steps below:

1. Put any value in Cell A1. For this tutorial, you will find the a value Jacobs

2. Now, Press F11 to open Visual Basic window or follow step 2 from the previous tutorial to get Code view.

3. On VB screen, under the click event for CommandButton1, enter the following code:

MsgBox “Welcome to my tutorial Mr. ” & Range(“A1”).Value

4. Close the VB screen and Click the command button on the worksheet. Result will be displayed as in figure below.

figure below

Note: In this tutorial, you will observe the use of & sign which is used as an operator to concatenate (join) two strings.