6
How to insert messages using the MsgBox function This function is useful for displaying information. The syntax for the MsgBox function is MsgBox (prompt, buttons, title) Where prompt = the text Excel displays in the message box Buttons =optional Title =optional 1.Open Excel 2. Open VB editor i.e Alt + F11 key 3. Click Developer Insert Choose command button (form control) 4. Click New 5. Type as follows Sub Button3_Click() MsgBox "Hello", vbExclamation End Sub 6. Rename the command button as necessary 7. Clcik the button and you will see : How to Insert Items in a ComboBox (Using a command button)

Notes_The MsgBox Function

Embed Size (px)

DESCRIPTION

qwerty

Citation preview

How to insert messages using the MsgBox function

This function is useful for displaying information. The syntax for the MsgBox function is MsgBox (prompt, buttons, title)Where prompt = the text Excel displays in the message box Buttons =optional Title =optional

1.Open Excel2. Open VB editor i.e Alt + F11 key3. Click Developer Insert Choose command button (form control)4. Click New

5. Type as follows

Sub Button3_Click()MsgBox "Hello", vbExclamationEnd Sub

6. Rename the command button as necessary7. Clcik the button and you will see :

How to Insert Items in a ComboBox (Using a command button)

1.Open Excel2. In Sheet1 of the workbook, type the following in cells A3 to A6. Formic acid Lactic acid Acetic acid Nitrous acid 2. Open VB editor i.e Alt + F11 key3. Click Developer Insert Choose command button (form control)4. Insert UserForm5. Place a Combobox on the Userform6. Place a command button on the form7. Double-click the commandbutton to insert Visual Basic code Assume that name of command button is cmdAcid and Combobox is cboAcid

Private Sub cmdAcid_Click() Worksheets(Sheet1).Activate cboAcid.AddItem Range (A3) cboAcid.AddItem Range (A4) cboAcid.AddItem Range (A5) cboAcid.AddItem Range (A6)

End Sub8. Run the program and click the command button. 9. Click the combobox and the list of the acids will be displayed.

How to Insert Items in a ComboBox (without a command button-using userform initialize)

1. Insert a combo box and name it cboAcid.2. Double-click the combo box to open the code window.3. Click the left combobox on the screen to and choose Userform (Fig. 1)4. Click the right side of the combo-box and choose initialize. (Fig. 2)5. Type the following codePrivate Sub UserForm_Initialize() Worksheets(Sheet1).Activate cboAcid.AddItem Range (A3) cboAcid.AddItem Range (A4) cboAcid.AddItem Range (A5) cboAcid.AddItem Range (A6)

End Sub6. Run the program and click the command button. 7. Click the combobox and the list of the acids will be displayed.8. 9. Fig. 1

Fig. 2 How to Insert Items in a ComboBox (in a worksheet)

1. In Sheet1 of the workbook, type the following in cells A3 to A6. Formic acid Lactic acid Acetic acid Nitrous acid 2. Insert a combobox on the worksheet. (In developer tab, choose Insert > Combobox)3.

4. Right-click the combobox and choose format control

5.

6. Click new

7. Enter $A$3:$A$6 for the input range. Click ok

How to display or hide a userform

Assume that you have created 3 userforms: frmMenu, frmStrong Acid and frmWeakAcidThe frmMenu form can link to either the Strong Acid form or a Weak acid form.

For the command button go to Strong Acid page, the code is frmStrongAcid.show

For the command button go to Weak Acid page, the code is frmWeakAcid.show

How to hide the strong acid or weak acid page i.e go back to main page

The code for the command button in the strong acid page is frmStrongAcid.hide

and for the weak acid page frmWeakAcid.hide