Sunteți pe pagina 1din 3

Test Your Skills User Interactions

File: Test Your Skills User Interactions.xslm

Summary: In this Test Your Skills exercise you will be using Input Boxes, Message Boxes, Macros, and
Decision Structures to create an interactive worksheet. The worksheet will allow users to quickly filter
the Sales Report by Salesperson. If the user does not enter a name, or spell the name incorrectly, they
will receive a message box asking if they would like to try again. There is a button on the worksheet to
perform the filter, and another to clear the filter.

Steps: See the steps on page 2.


When you have finished, or need help, see the VBA code on page 3.

Remember: There are multiple ways to program in VBA. Your code might be slightly different than my
code.

IsaBel Harrison | Udemy.com


Steps:

1. Open the VBE

2. In the VBE, open Module 1.


You will write your code in the FilterBy procedure.

3. Declare Filtering as a String.


Filter will be the variable that stores the salespersons name that the user types into the input
box.

4. Declare MessageAnswer as a Byte.


MessageAnswer will store the value of the Yes/No buttons on the message box.

5. Create the input box with the text, and title seen in the image on page 1.

6. Assign the input box to the Filtering variable.

7. Create the Decision Structure that will carry out the filtering.
You can use the FilterShephard, and FilterSmith macros as the filter criteria when you get
started, then create more filter criteria on your own.
REMEMBER: If the user does not enter a name, or spell the name incorrectly, they will receive a
message box asking if they would like to try again. If the user clicks Yes, then reopen the input
box. See message box on page 1 for verbiage.

8. Save, and test your code.

IsaBel Harrison | Udemy.com


Solution:

Sub FilterBy()

Dim Filtering As String

Dim MessageAnswer As Integer

'Create the Input Box

Filtering = InputBox("Enter a Salesperson's name to filter the Report:" & _

vbCrLf & "NOTE: Case Sensitive", "Sales Report")

'Create the Decision Structure that Calls on Filters

Select Case Filtering

Case "Shephard"

Call FilterShephard

Case "Smith"

Call FilterSmith

Case Else

MessageAnswer = MsgBox("You did not enter a name, or have incorrect


spelling." & _

vbCrLf & "Would you like to try again?", vbYesNo)

If MessageAnswer = 6 Then

Call FilterBy

End If

End Select

End Sub

IsaBel Harrison | Udemy.com

S-ar putea să vă placă și