VBA Chapter 2 Beyond the Classroom 1

Total Page:16

File Type:pdf, Size:1020Kb

VBA Chapter 2 Beyond the Classroom 1

VBA Chapter 2 Beyond the Classroom 1

The Instructions worksheet contains four buttons. You need to insert command buttons and assign name and caption properties.

Code the Attendees button to unprotect the Budget worksheet and then display the following input box to request information from the user. When the user enters the value and clicks OK, the procedure saves the user input in the appropriate cell in the Budget worksheet and then protects the Budget worksheet again. Code the Income button to unprotect the Budget worksheet and then display the Income form shown below. Create the form, set the control properties, and create a UserForm Initialization procedure that sets the focus to the first text box. Use the SelStart property, SelLength property, Len(.Text) function, and the SetFocus function so that when the text box receives focus, it also selects the existing text. Use Help to learn how to use these properties.

You need to bind the text boxes to the appropriate cells on the Budget worksheet so that they display current values and that when the user clicks OK, the new values are stored in the bound cells. Close the form and protect the Budget worksheet when the user clicks OK.

Code the Expenses button to display the Expenses form that you need to create. Bind the text box controls to the appropriate cells in the Budget worksheet. Declare variables for the attendees (obtained from the appropriate cell in the Budgets worksheet), cost of a chair usage per person, total calculated cost for chair rentals, meal per person, and total meal cost (calculated). Store the two calculated values in their respective cells in the Budgets worksheet. Close the form and protect the Budget worksheet when the user clicks OK.

Create a UserForm Initailization method to set the focus and select the existing value in the first text box when the form first loads. Code the Display Budget button to display the Budget worksheet. Create a button on the Budget worksheet that, when clicked, returns to the Instructions worksheet. Check all procedures to ensure correct unprotecting and protecting of the Budget worksheet. Users should not be able to directly enter or edit data on the Budget worksheet. All changes are made through the input box and forms.

Recommended publications