Open a new workbook using a new module, write the VBA code in Listings 9.4 and 9.5. Run the subprogram to make sure it works correctly. Write a function called TrebleMe that takes a integer value and multiplies it by 3. Test this function procedure by using a blank worksheet and enter =TrebleMe (30) in cell B3.

Write a function called AddTwo that will take two integer parameters and return their sum.

Write a function called AddTwo that will take two parameters as string values and return their sum as a string value.

Open the weeklysales sheet of the SALESMAN w orkbook. Create a function called IsValidRepName that will take a repName as a parameter and returns True if the repName exists in the range on the w orksheet. Test y our function using =IsRepName (Jack), and =IsRepName (Rhiannon) using any blank cells on the worksheet.

Write the following sub procedure for testing the function.

Sub TestIsValidRepName () Dim tryRep As String

TryRep = InputBox "enter a repName for testing" MsgBox "the repName is valid: " & IsValidRepName (tryRep) End Sub

Amend your function from (3) so that it has an extra parameter to pass back the address of the cell in which that repName is found. Test your function.

Amend your function from (4) so that it has a third extra parameter to pass back the value of the miles to date for that RepName. Test your function.

Try out the pass ByRef and ByVal example in 5.4 and 5.5.

Study the following sub procedure and try to find out what it does.

Sub IsActiveCellEmpty()

Dim stFunctionName As String, stCellReference As String stFunctionName = "isblank" StCellReference = ActiveCell.Address

MsgBox Evaluate (stFunctionName & "(" & stCellReference & ")") End Sub

10 Using forms

User forms 188

The form design 194

Event procedures 199

Creating event procedure code . . 200

Creating context sensitive Help . . 203

Designing for the end user 209

Exercises 212

0 0

Post a comment