E00EX10.qxp 5/24/2010 1:55 AM Page 501

Workshops w Introduction

The Workshops are all about being creative and thinking outside of the box. These workshops will help your right-brain soar, while making your left-brain happy; by explaining why things work the way they do. Exploring possibilities is great fun; however, always stay grounded with knowledge of how things work.

Getting and Using the Project Files

Each project in the Workshops includes a start file to help you get started with the project, and a final file to provide you with the results of the project so you can see how well you accomplished the task.

Before you can use the project files, you need to download them from the Web. You can access the files at www.perspection.com in the software downloads area. After you download the files from the Web, uncompress the files into a folder on your hard drive to which you have easy access from your Microsoft Office program. Project 1: Creating a Drop-Down List

Skills and Tools: Create a drop-down list

Entering data in a worksheet can be tedious and repetitive. To make the job easier and get consis- tent accurate data, you can create a drop-down list of entries you define. To create a drop-down list, you create a list of valid entries in a single column or row without blanks, define a name, and then use the List option in the Data Validation . To enter data using a drop-down list, click the cell with the defined drop-down list, click the list arrow, and then click the entry you want.

The Project

In this project, you'll learn how to create a drop-down list from a named range of cells for use in conditional formatting.

The Process 1 Open Excel 2010, open DropDown_start.xlsm, and then save it as DropDown.xlsm. 2 Click the Numbers . w 501 E00EX10.qxp 5/24/2010 1:56 AM Page 502

3 Select the cell range of 6 7 8 numbers in column A, (A1:A50). To create a drop-down list, you need a single column or row without blanks.

4 Click the Name box, type Numbers, and then press Enter.

5 Click the Form Controls Sheet tab. 6 Select cell B1.

7 Click the Data tab. 8 Click the Data Validation .

9 Click the Settings tab. 5 9 10 10 Click the Allow list arrow, and then click List. 11 Click the Source box, and then type =Numbers. 12 Click OK. 13 Click the Name box, type StartNum, and then press Enter. 14 Select cell D2.

15 Repeat steps 8 through 13, and name the cell EndNum. 16 Select cell B1, click the drop-down list, and then select a number. 11 12

17 Select cell D1, click the 18 17 drop-down list, and then select a number.

18 Click the Save button on the Quick Access .

The Results Finish: Compare your completed project file with the results file w DropDown_results.xlsm. 502 Workshops E00EX10.qxp 5/24/2010 1:56 AM Page 503

Project 2: Adding a Form Control

Skills and Tools: Insert a Form Control

Form controls are objects that users can interact with to enter or manipulate data. A control is a component on a worksheet used to display information or accept user input. For example, you can add a control to your worksheet so that users can turn an option on and off. You can select a control from the Developer tab and drag to create the control directly on your worksheet.

The Project

In this project, you'll learn how to insert a check box form control into a worksheet to control formatting.

The Process 1 Open Excel 2010, open 8 4 3 2 FormControl_start.xlsm, and then save it as FormControl.xlsm. 2 Click the Developer tab. 3 Click the Design button (highlighted), if available.

4 Click the Insert button, and then click the Check Box (Form Control); located on the top row. 5 Drag (pointer changes to a plus sign) to draw the form control in a blank area of the worksheet. When you point to a control in Excel, you will see the pointer cursor. To select a control, right-click the object, and then click off the . Check box 6 Select the check box object (if necessary), select the text to the right of the check box, and then press Delete. 7 Drag the right-middle resize handle (circles) to the size check box control to display only the check box. 8 Drag the check box control to cell E1 below the text Check box status. 9 Right-click the check box control, and then click Format Control. w Workshops 503 E00EX10.qxp 5/24/2010 1:57 AM Page 504

10 Click the Control tab. 11 10 11 Click the Checked option. 12 Click the Collapse Dialog button, click cell E2, and then click the Expand Dialog button. 13 Select the 3-D shading check box. 14 Click OK. 15 Select the check box control (if necessary), click the Name box, type a CheckBoxSwitch, and then press Enter.

16 Click the Design Mode button (not highlighted), and then click a blank cell to deselect the check box control. 13 12 14 17 Click the check box to turn it on and off. The contents of cell E2 toggles 18 17 16 between TRUE and FALSE.

18 Click the Save button on the Quick Access Toolbar.

The Results Finish: Compare your completed project file with the results file FormControl_results.xlsm. Project 3: Adding Conditional Formatting

Skills and Tools: Conditional Formatting

You can make your worksheets more powerful by setting up conditional formatting, which lets the value of a cell determine its formatting. For example, you might want this year’s sales total to be dis- played in red and italics if it’s less than last year’s total, but in green and bold if it’s more. The for- matting is applied to the cell values only if the values meet the condition that you specify. Otherwise, no conditional formatting is applied to the cell values.

The Project

In this project, you'll learn how to add conditional formatting to a named range and include form w controls. 504 Workshops E00EX10.qxp 5/24/2010 1:57 AM Page 505

The Process 1 Open Excel 2010, open ConditionalFormat_start.xlsm, and then save it as ConditionalFormat.xlsm. 2 Select the cell range A3:A32. 5 3 Click the Home tab. 4 Click the Conditional Formatting button, and 6 then click New Rules. 5 Click Use a formula to determine which cells to format. 6 Type the formula 14 7 =AND($A3>=StartNum,$A3<=EndNum,CheckBoxSwitch) 7 Click Format. 8 Click the Fill tab. 9 Click Fill Effects.

8 10

9 13 11 12 10 Click the Color 2 list arrow, and then select a color. 11 Click a gradient option, and then select a gradient.

12 Click OK to close the Fill Effects dialog box. 13 Click OK to close the Format dialog box. w Workshops 505 E00EX10.qxp 5/24/2010 1:57 AM Page 506

14 Click OK. 15 Click the Conditional Formatting button, and then click Manage Rules. 16 Select the Stop If True check box to provide compatibility error checking.

17 Click OK.

Conditional formatting rule 17 16 The Results Finish: Compare your completed project file with the results file ConditionalFormat_results.xlsm. Project 4: Creating a VBA Script

Skills and Tools: Visual Basic for Applications script

Instead of pressing the Caps Lock key every time you want to turn capitalization on and off, you can create a VBA script to change cell contents to upper case. This can be useful when you have col- umn data, such as two-letter US state abbreviations, in a worksheet. You can type the state abbre- viation in lower case and let the VBA script change it for you.

The Project

In this project, you'll learn how to create a VBA script to change cell contents in a designated range to uppercase.

The Process 4 5 6 1 Open Excel 2010, open CAPS_start.xlsm, and then save it as CAPS.xlsm. 2 Click the Developer tab. 3 Click the Visual Basic button. 4 Double-click the Sheet1(Vendors) object. The Object windows opens.

5 Click the Object list arrow, and then click Worksheet. 6 Click the Properties list arrow, and then click w Change. 506 Workshops E00EX10.qxp 5/24/2010 1:58 AM Page 507

7 Type the VBA code that appears in the following illustration:

Common Cell and Range References

Reference Example Description Range(“A1”) Cell A1 Range(“A1:B5”) Cells A1 through B5 Range(“C5:D9,G9:H16”) Cells C5 through D9 and cells G9 through H16 Range(“A:A”), Range(“A:C”) Column A, Columns A through C Range(“1:1”), Range(“1:5”) Row 1, Rows 1 through 5 Range(“1:1,3:3,8:8”) Rows 1, 3, and 8 Range(“A:A,C:C,F:F) Columns A, C, and F)

8 Click the Save button on the 11 10 Standard toolbar.

9 Click the Close button on the Visual Basic Editor to return to Excel. 10 Type state abbreviations in column E. After you press Enter, cell contents changes to uppercase. 11 Click the Save button on the Quick Access Toolbar.

The Results Finish: Compare your completed project file with the results file CAPS_results.xlsm. w Workshops 507 E00EX10.qxp 5/24/2010 1:58 AM Page 508

Project 5: Creating a VBA Interface

Skills and Tools: ActiveX Controls and Visual Basic for Applications (VBA) form

An ActiveX control is a software component that adds functionality to an existing program. An ActiveX control supports a customizable, programmatic interface using VBA, which you can use to create your own functionality, such as a form. Excel includes several pre-built ActiveX controls— including a , , command button, and check box—to help you create a user interface.

The Project

In this project, you'll learn how to create a form using VBA that allows users to input information using a series of dialogs, like a wizard, and use buttons to clear information and save the work- sheet.

The Process 1 Open Excel 2010, open VBAForm_start.xlsm, and then save it as VBAForm.xlsm. ➤ Insert an ActiveX control. 4 3 2 2 Click the Developer tab. 3 Click the Design Mode button (highlighted).

4 Click the Insert button, and then click CommandButton (ActiveX Control). 5 Drag to create a button control on the worksheet. The ActiveX control is labeled CommandButton1. 6 Repeat steps 4 and 5 to add CommandButton2 and CommandButton3 to the worksheet. ➤ Set control properties. 1 Click the CommandButton1 control to select it on the worksheet. 2 Click the Properties button. 3 In the Properties window, change the Caption text to Gather Info; change the BackColor to Inactive Title Bar (click the box next to the property to display a list arrow); change the Height w to 24.75; and change the Width to 81. 508 Workshops E00EX10.qxp 5/24/2010 1:59 AM Page 509

4 Click the CommandButton2 control to select it on the worksheet, change the Caption text to Clear Results, and then make the same remaining changes in step 3. 5 Click the CommandButton3 control to select it on the 10 7 9 8 worksheet, change the Caption text to Save Results, and then make the same remaining changes in step 3.

6 Click the Close button in the Properties window.

7 Click the Page Layout tab. 8 Click the Align button, and then click Align Center to align center the ActiveX control buttons.

9 Click the Align button, and then click Distribute Vertically to distribute vertically the ActiveX control buttons.

10 Click the Save button on the Quick Access Toolbar. ➤ Add VBA functionality to the control. 1 Click the Developer tab. 2 Click the Visual Basic button. 3 In Project Explorer, double-click the Sheet(Annuity) object, if necessary, to open the Code Window.

4 Click the Object box list arrow at the top of the Code Window, and then click CommandButton1. 5 In the Code window, type the VBA code that appears in the following illustration:

This code clears the current contents of cells B3 through B6, moves the selection out of the way to cell A7, and then assigns named cell values, such as Present_Value, the number entered using the InputBox function. The first argument in the InputBox function is the text you want in the dialog box, and the second argument is the dialog box title. w Workshops 509 E00EX10.qxp 5/24/2010 1:59 AM Page 510

6 Repeat steps 4 through 6 to add VBA code for CommandButton2 and CommandButton3 to the control that appears in the following illustration:

This code creates a Save dialog box. The code uses the MsgBox function to display a dialog box when you click the button (CommandButton2). The first argument in the MsgBox function is the text you want in the dialog box, and the second argument is the type of buttons you want to use (in this case, Yes and No), and the third argument is the type of you want to use in the dialog box. See the table at the end of this project for different types of dialog box buttons and icons.

This code creates a dialog box to clear the current contents of cells B3 through B6.

7 In Project Explorer, double-click the ThisWorkbook object, if necessary, to open the Code Window. 8 Type the VBA code that appears in the following illustration:

This code creates a dialog box when you open the workbook, displaying text and the username of the workbook (in this case Tim Todd). This code is placed in the ThisWorkbook object and uses the procedure Sub Workbook_Open(), so it gets executed when you open the workbook.

9 Click the Save button on the Standard toolbar. 10 Click the Close button on the Visual Basic Editor window to return to Excel. 11 Click the Design Mode button (not highlighted). 12 Click the Clear Results button, and then click Yes to clear client information.

w 12 510 Workshops E00EX10.qxp 5/24/2010 1:59 AM Page 511

13 Click the Gather Info button, enter annual salary, click OK, enter interest rate, click OK, enter the term in years, click OK, enter a reinvest percentage, and then click OK. Enter correct values. You’ll learn how to add error checking later.

14 Click the Save Results button, and then click Yes to save the worksheet.

15 Click the Save button on the Quick Access Toolbar. 16 Click the File tab, and then click Close. 17 Click the File tab, click Recent, and then click VBAForm_results on the Recent Workbooks list. The message alert dialog box opens. 18 18 Click OK. 19 Click the Save button on the Quick Access Toolbar. ➤ Add VBA conditional functionality to the control. 1 Click the Developer tab. 2 Click the Visual Basic button. 3 In Project Explorer, double-click the Sheet(Annuity) object, if necessary, to open the Code Window.

4 Click the Object box list arrow at the top of the Code Window, and then click CommandButton1. 5 In the Code window, change the VBA code to add error checking to the data input that appears in the following illustration:

Changed code w Workshops 511 E00EX10.qxp 5/24/2010 1:59 AM Page 512

Common MsgBox Function Arguments

Constant Value Description vbOKOnly 0 Display OK button only vbOKCancel 1 Display OK and Cancel buttons vbAbortRetryIgnore 2 Display Abort, Retry, and Ignore buttons vbYesNoCancel 3 Display Yes, No, and Cancel buttons vbYesNo 4 Display Yes and No buttons vbRetryCancel 5 Display Retry and Cancel buttons vbCritical 16 Display Critical Message icon vbQuestion 32 Display Warning Query icon vbExclamation 48 Display Warning Message icon vbInformation 64 Display Information Message icon vbDefaultButton1 0 First button is default vbDefaultButton2 256 Second button is default vbDefaultButton3 512 Third button is default vbDefaultButton4 768 Fourth button is default

6 Click the Save button on the Standard toolbar. 7 Click the Close button on the Visual Basic Editor window to return to Excel. 8 8 Click the Gather Info button, enter annual salary, click OK, enter interest rate, click OK, enter the term in years, click OK, enter 0 (as a reinvest percentage), re- enter a reinvestment percentage greater than 0, and then click OK. 9 Click the Save button on the Quick Access Toolbar.

The Results Finish: Compare your completed project file with the presentation w VBAForm_results.xlsm. 512 Workshops E00EX10.qxp 5/24/2010 2:00 AM Page 513

Want More Projects

You can access and download more workshop projects and related files at www.perspection.com in the software downloads area. After you download the files from the Web, uncompress the files into a folder on your hard drive to which you have easy access from your Microsoft Office program.

Get Everything on DVD

Instead of downloading everything from the Web, which can take a while depending on your Inter- net connection speed, you can get all the files used in this book and much more on the Microsoft Office 2010 On Demand DVD. The DVD contains task and workshop files, tips and tricks, keyboard shortcuts, transition helpers from 2003 or 2007 to 2010, and other goodies from the author.

To get the Microsoft Office 2010 On Demand DVD, go to www.perspection.com.

w Workshops 513 E00EX10.qxp 5/24/2010 2:00 AM Page 514