Open a new workbook. G o to the VBE and insert a new form. P lace on it three textboxes, with the labels FIRST, SECOND and RESULT, and three b uttons labelled MAXIMUM, MINIMUM and QUIT - the layout should be similar to that in Figure 10.3. Write event handlers for the b uttons. The form should accept two integers and show in the RESULT either the maximum or minimum, or quit the program, depending on the button clicked. Check y our program by entering 6 in the FIRST and 15 in the SECOND textbox.

Open a new workbook. Write a Workbook.SheetActivate event procedure that will fill the cells A2, B2 and C2 with the values 1, 2 and 3 respectively whenever the user activates a worksheet. Test the results. Study the following code and explain what you think it does:

Private Sub Workbook_NewSheet (ByVal Sh As Object)

Range ("A1:A10").Value = "Month" End Sub

Open a new workbook. Write a Worksheet_Activate event procedure that will display the message "You have entered Sheet3" whenever Sheet3 becomes the active sheet. Test the procedure.

Open the SALESMAN workbook and select the summary worksheet. Create the form shown in Figure 10.17 and write the event code that will enable a user to enter a rep name from the rep name list, and enter the highest and lowest sales in the b oxes from the w orksheet. If the user enters an invalid rep name, i.e., one that is not in the list, then the form should be unloaded. (Hint: You can use the procedure shown on page 137 to find the rep name from the list and then use the offset method to reference and transfer the highest and lowest sales to the form.)

Figure 10.17

Figure 10.17


ASCII codes 214

Events 215

Worksheet events 215

Workbook events 216

Chart events 217

Application events 218

Further reading 219

Useful VBA websites 220

0 0

Post a comment