15
PMI Online Education Name Ranges and LookUp Functions Microcomputer Applications

Name Ranges and LookUp Functions - repo.pmi.edurepo.pmi.edu/online/Master_Documents/CPT301_Microcomputer... · Retrieving Data Using an HLOOKUP Table ... Create a VLOOKUP function

Embed Size (px)

Citation preview

Page 1: Name Ranges and LookUp Functions - repo.pmi.edurepo.pmi.edu/online/Master_Documents/CPT301_Microcomputer... · Retrieving Data Using an HLOOKUP Table ... Create a VLOOKUP function

PMI Online Education

Name Ranges and LookUp Functions Microcomputer Applications

Page 2: Name Ranges and LookUp Functions - repo.pmi.edurepo.pmi.edu/online/Master_Documents/CPT301_Microcomputer... · Retrieving Data Using an HLOOKUP Table ... Create a VLOOKUP function

How to Open a Template 2

Table of Contents Objective 5: Create Range Names .......................................................................................................................................................................................................... 3

Naming a Range ................................................................................................................................................................................................................................... 3 Modifying a Name Range ..................................................................................................................................................................................................................... 4 Using Row and Column Titles to Name a Range .................................................................................................................................................................................. 5 Delete a Range Name ........................................................................................................................................................................................................................... 5

Objective 6: Ensure Data Integrity .......................................................................................................................................................................................................... 6

Creating a Validation List ..................................................................................................................................................................................................................... 6 Objective 7: Use Lookup Functions ......................................................................................................................................................................................................... 7

Retrieving Data Using a Name Range in a VLOOKUP Formula ............................................................................................................................................................. 7 Removing Error Codes and Using IFERROR Function in a Nested IF Statement .................................................................................................................................. 8 Creating an HLOOKUP Table .............................................................................................................................................................................................................. 10 Retrieving Data Using an HLOOKUP Table ......................................................................................................................................................................................... 11 Hiding Rows Containing Lookup Tables ............................................................................................................................................................................................. 12 Unlocking Cells for Data Entry and Protecting a Worksheet ............................................................................................................................................................. 13 Hiding Formulas in the Worksheet .................................................................................................................................................................................................... 14 Setting a Print Area ............................................................................................................................................................................................................................ 14 Saving the Order Form as a Template ................................................................................................................................................................................................ 15

Page 3: Name Ranges and LookUp Functions - repo.pmi.edurepo.pmi.edu/online/Master_Documents/CPT301_Microcomputer... · Retrieving Data Using an HLOOKUP Table ... Create a VLOOKUP function

How to Open a Template 3

Naming a Range

Objective 5: Create Range Names

Naming a Range

• Start Excel and open the provided file named Deni’s_Order_Form. • Save the file as Deni’s_Order_Form_Firstname_Lastname in the Excel

Lessons folder. o Review the contents of the worksheet, looking at column labels and

the list of products that can be ordered. • Select the range A4:D7 and click the Formulas tab. In the Defined

Names group, point to Define Name to display the ScreenTip. • Click the Define Name button and in the Name box, type Products. Click

OK. o Excel has range naming rules. Range Names must

o Be careful not to use a Range Name that could be confused as a cell reference, such as, A1 or RS2010.

start with text characters, not numbers, and cannot have spaces. Two words can be joined with an underscore; for example, to enter the Name "purchase date", you should type purchase_date.

o The number of Range Names you define is limitless. Define unique Range Names for each workbook. Using Range Names that resemble Range Names in other worksheets will get very complicated and confusing. It is also possible to apply a range name to individual cells.

• Notice the range name appears in the Name Box. Click an empty cell to deselect the range. Return to the range by clicking the Name Box arrow and selecting Products.

• Save the workbook.

Page 4: Name Ranges and LookUp Functions - repo.pmi.edurepo.pmi.edu/online/Master_Documents/CPT301_Microcomputer... · Retrieving Data Using an HLOOKUP Table ... Create a VLOOKUP function

How to Open a Template 4

Modified Name Range

Modifying a Name Range

• Deselect the Products range area. Right-click cell A5 and insert a new row. Type the following information in the new row: o Novel of the Month o 6101 o 8.50 o 10

• On the Formula Bar, click the Name Box arrow and click Products to ensure that the new row has been added to the named range.

• Navigate to cell A9 and type the following information in this row: o I Love Books Mug o 1238 o 8.95 o 37

• In the Name Box, click Products to see that the range does not include the new content.

• On the Formulas tab, in the Defined Names group, click the Name Manager Button to open the Name Manager dialog box. If necessary, move the box so that columns A:D are visible. In the dialog box, click Products and click the Edit button.

• In the Edit Name dialog box, click the Collapse Dialog Box button at the end of the Refers to box. Return to the worksheet and select the range A4:D9. In the Edit Name–Refers to box, click the Expand Dialog Box and point out that the Refers to box now includes row 9. Click OK, and then click Close.

• Copy the formatting for cell A8 by right-clicking and selecting the Format Painter from the Mini toolbar. Click cell A9 to format it.

• Select the range A3:D9 and on the Home tab, in the Font group, click the Dialog Box Launcher. In the Format Cells dialog box, click the Border tab. In the Presets area, click None to clear existing borders in the range. Click Outline to add an exterior border around the selected range. Click OK.

• Click cell A1 and notice the new formatting and border for the Products range. In the Name Box list, click Products to verify the revised range works properly.

• Save the workbook.

Page 5: Name Ranges and LookUp Functions - repo.pmi.edurepo.pmi.edu/online/Master_Documents/CPT301_Microcomputer... · Retrieving Data Using an HLOOKUP Table ... Create a VLOOKUP function

How to Open a Template 5

Underscores in Names

Creating a New Name

Using Row and Column Titles to Name a Range

• Select the range A4:B9. On the Formulas tab, in the Defined Names group, click the Create from Selection button. In the Create Names from Selection dialog box, place a check in the Left column choice, if necessary. No other boxes should be checked. Click OK.

• Click the Name Box arrow to display the available ranges. Underscores are used between words instead of hyphens or spaces and before range names that begin with a number.

• From the list, click Celtic Bookmarks and observe that the cell containing the code for Celtic Bookmarks is selected.

• Save the file.

Deleting a Range Name

• Click cell A7 and revise the text to 2010 Calendar and press Enter. • Right-click the row 7 heading and insert a new row. Add the following

text in the new row: o Mini Book Light o 3128 o 10.97 o 8.8

• Click cell B7 and click the Name Box. Replace the highlighted cell reference with the text Mini_Book_Light and press Enter. This is an alternate way of creating a named range.

• On the Formulas tab, in the Defined Names group, click the Name Manager button. Click New and type _2010_Calendar in the New Name box. Remember to include the leading underscore. Select the range shown in the Refers to box and replace it by clicking in cell B8. Notice the inclusion of absolute cell references and the sheet name in the new range.

• Click OK and return to the Name Manager dialog box. In the list of ranges, note that _16_Month_Calendar and _2010_Calendar both refer to the same range. Since the 16 Month Calendar designation no longer exists, delete it by highlighting it in the Name Manager dialog box and clicking Delete.

• Confirm the warning message by clicking OK, close the dialog box. • Save the file.

Page 6: Name Ranges and LookUp Functions - repo.pmi.edurepo.pmi.edu/online/Master_Documents/CPT301_Microcomputer... · Retrieving Data Using an HLOOKUP Table ... Create a VLOOKUP function

How to Open a Template 6

Creating Data Validation

Testing the Validation

Objective 6: Ensure Data Integrity

Creating a Validation List

Use a validation list to help ensure data integrity. By limiting what can be entered in certain cells, there is less chance of data being incorrectly entered. • Select the range A3:A10. On the Formulas tab, in the Defined Names

group, click Create from Selection. Make sure the checkbox for Top Row is checked and click OK. The new range will be named Item.

• Select the range A25:A39. On the Data tab, in the Data Tools group, click the Data Validation button.

• In the Data Validation dialog box, be sure that the Settings tab is selected. Then, under Validation criteria, click the Allow box arrow. From the list, select List.

• At the end of the Source box, click the Collapse Dialog Box button and from the worksheet, select A4:A10. Click the Expand Dialog Box button and note that the Source box displays the range name =Item instead of the cell range.

• Click the Input Message tab and in the Title box, type Products. In the Input Message box, type Choose from the list of products shown

• Click the Error Alert tab and review the choices in the Style box. Select the default, Stop. In the Title box, type Incorrect Choice. In the Error message box, type Please choose a product from the item list. Click OK.

• Scroll down to the selected range–A25:A39. Notice the list arrow that displays to the right of cell A25 and the input message box that was created. Click cell A25 and type Bookmark, then press Enter. Observe the Incorrect Choice stop message that displays. Click Cancel to remove the invalid entry. In the Item column, click in several cells and note how the list arrow displays. Return to cell A25, click the list arrow, and choose Celtic Bookmarks. Note that this choice is entered in the cell.

• On the Quick Access Toolbar, click the Undo button to remove this selection. Select the range D25:D39 in the Data Tools group, click the Data Validation button. On the Settings tab, in the Allow list, select Whole Number. From the Data box arrow, select between and set the Minimum to 1 and the Maximum to 250.Click the Error Alert tab and from the Style box, select Warning. In the Error Message box, type Supervisor permission needed for orders over 250 and click OK.

• Test the validation by clicking cell D25 and entering 260. • Finish by clicking Cancel to remove the entry. • Save the workbook.

Page 7: Name Ranges and LookUp Functions - repo.pmi.edurepo.pmi.edu/online/Master_Documents/CPT301_Microcomputer... · Retrieving Data Using an HLOOKUP Table ... Create a VLOOKUP function

How to Open a Template 7

VLOOKUP Formula for Cell C25

Objective 7: Use Lookup Functions

Retrieving Data Using a Name Range in a VLOOKUP Formula

• Select the range A3:D10. On the Data tab, in the Sort & Filter group, click the Sort button. In the Sort dialog box, under Column, click the Sort by box arrow and click Item. The Sort on box should display Values and the Order should be A to Z. If necessary, place a check in the My data has headers checkbox.

• Click OK, and notice the products are now sorted alphabetically by item. Click cell A25, click the list arrow, and select Mini Book Light.

• Click cell B25 and on the Formulas tab, in the Function Library group, select Lookup & Reference. Click VLOOKUP from the end of the list and look over the Function Arguments dialog box. o Lookup value is located in the cell with the value to be looked up. o Table array is the defined range containing the data to be retrieved. o Column index number is the column number in the table array

containing the desired result. o Range lookup is an optional argument used to determine if the match

must be exact or just close. • In the Lookup_value box, type a25. In the Table_array argument, click

the Collapse Dialog Box button. In the worksheet, select the range A4:D10. Click the Expand Dialog Box button to return to the dialog box. Note that the range name Products is used in place of the cell references.

• In the Col_index_num box, type 2 and in the Range_lookup box, type False. Click OK.

• Repeat this process for cell C25, using a25 for the Lookup_value and Products for the Table_array value. Type 4 in the Col_index_num box and False in the Range_lookup box. Click OK and note the correct weight has been added to the order.

• Create a VLOOKUP function in cell F25 that will lookup the value in cell A25 and retrieve the price from the third column of the Products range.

• Type 5 in cell D25. In cell E25, type the formula =c25*d25/16 to calculate the weight of the item in pounds. In cell G25 type the formula =f25*d25 and press Enter.

• If 5 Mini Book Lights are ordered, they would cost $54.85 and weigh 2.75 pounds.

• Save the worksheet.

Page 8: Name Ranges and LookUp Functions - repo.pmi.edurepo.pmi.edu/online/Master_Documents/CPT301_Microcomputer... · Retrieving Data Using an HLOOKUP Table ... Create a VLOOKUP function

How to Open a Template 8

Screen Tip

Removing Error Codes and Using IFERROR Function in a Nested IF Statement

A Nested IF function is a second IF function placed inside the first to test additional conditions. Nesting IF functions increase the flexibility of the function. The IF function can be nested up to 7 times. The second IF function is usually placed in the value_if_true argument place of the formula. That way, if the logical test is true, it will look for the logical test of the IF function in the value_if_true location of the first IF. The IFERROR function Returns a value you specify if a formula evaluates to an error; otherwise, returns the result of the formula. Use the IFERROR function to trap and handle errors in a formula. • Select range B25:G25 and copy the formulas down through row 39. Select

range D25:D39 and delete the numbers from the Quantity column. #N/A is the error value that means "no value is available”. Other error notations: #DIV/0 – Cannot divide by zero #NAME? – Does not recognize a name you used in a formula #VALUE – Cannot use a text field in a formula #REF – Cannot locate the reference #NUM – Invalid argument in a worksheet function #NULL – No common cell

• Navigate to cell B25. Modify the formula shown in the Formula Bar by positioning the insertion point between the equal sign and the V in VLOOKUP. Type IFERROR( to nest the VLOOKUP function inside it. IFERROR uses the following arguments: o Value is the argument to be checked. o Value if error is the resulting value displayed if an error is found.

• Position the insertion point at the end of the formula and type ,””) to complete the IFERROR function. On the Formula Bar, click Enter.

• Delete Mini Book Light from cell A25. Observe that there is no error in cell B25 but that other cells in the row still contain an error.

• Copy the formula in B25 down through cell B39. • Modify the formula in cell C25 by repeating the process in the steps above to

add the IFERROR function and arguments. Copy the revised formula down through cell C39. Notice the new error code that appears in cells E25:E39.

• Display the ScreenTip for cell E25. This error appears because the current IFERROR function specifies a blank cell but that the formulas in column E require a number to work correctly.

• Delete the formula in cell E25. On the Formulas tab, in the Function Library group, click the Logical button and click the IFERROR function.

• In the Function Arguments dialog box, in the Value box, type d25*c25/16 and in the Value_if_error box, type “” Click OK. Copy the formula in E25

Page 9: Name Ranges and LookUp Functions - repo.pmi.edurepo.pmi.edu/online/Master_Documents/CPT301_Microcomputer... · Retrieving Data Using an HLOOKUP Table ... Create a VLOOKUP function

How to Open a Template 9

Logical IFERROR Function Argument

down through cell E39. • Revise the formula in cell F25 using the IFERROR function to remove the

#NA error. Replace the formula in cell G25 with an IFERROR function that will eliminate the #VALUE! error code. Copy both formulas through row 39.

• Click cell A25 and from the selection list, select Mini Book Light. In cell D25, type the quantity 5

• Remember that it is important to verify formulas for accuracy. • Save the workbook.

Page 10: Name Ranges and LookUp Functions - repo.pmi.edurepo.pmi.edu/online/Master_Documents/CPT301_Microcomputer... · Retrieving Data Using an HLOOKUP Table ... Create a VLOOKUP function

How to Open a Template 10

HLOOKUP Table

Creating an HLOOKUP Table

• Select the ranges C25:C39 and E25:G43. Right-click and from the Mini toolbar, format the selection to use the Comma Style.

• Select the range F25:G25 and cells G40 and G43. Right-click and from the Mini toolbar, select the Accounting Number Format.

• Copy the format used in cell E39 by right-clicking, selecting the Format Painter button on the Mini toolbar, and applying the formatting to cell E40.

• With cell E40 still active, on the Formulas tab, in the Function Library group, click the AutoSum button to add the AutoSum function. The AutoSum range should be E25:E39. Repeat this process for cell G40 to sum the column.

• In cell G41, type the formula =G40*.07 to calculate state sales tax of 7%. • In cell G43, enter the SUM formula to total cells G40:G42. • In cell F3, type the title Shipping and Handling Charges. • Beginning in cell F4, enter the following data:

o Weight 0.5 5 10 o Ground 5.25 8.5 10.25 o Priority 6.5 10 12.5 o Next Day 10.5 15 25.5

• Select the range G5:I7 and use the Mini toolbar to format with the Accounting Style.

• On the Home tab, in the Editing group, click the Sort & Filter button to sort the range F4:I7 from A to Z.

• Beginning in cell F9, enter the following data: o Method Code o Ground 2 o Next Day 3 o Priority 4

• Select the nonadjacent ranges F3:I4, F5:F7, and F9:G9. Right-click and from the Mini toolbar, select the Fill Color button arrow. Select the third color in the seventh column–Olive Green, Accent 3, Lighter 60%. Select the range F3:I7 and on the Mini toolbar, click the Border button arrow. Select Thick Box Border. Using the Mini toolbar, center the range G4:I4. Select the range F9:G9 and apply a Thick Bottom Border. Add an Outside Border to the range F9:G12. Click on an empty cell to view the results.

• Select the range F4:I7. On the Formula Bar, click the Name Box, and type Shipping_and_Handling_Charges .

• Save the workbook.

Page 11: Name Ranges and LookUp Functions - repo.pmi.edurepo.pmi.edu/online/Master_Documents/CPT301_Microcomputer... · Retrieving Data Using an HLOOKUP Table ... Create a VLOOKUP function

How to Open a Template 11

Calculations Using HLOOKUP Formulas

Retrieving Data Using an HLOOKUP Formula

• In cell G18, type Priority. In cell G19, on the Formulas tab, in the Formula Library group, click Lookup & Reference to insert the VLOOKUP function.

• In the Lookup_value box, type g18 In the Table_array box, click the Collapse Dialog Box button, and in the worksheet, select the range F10:G12. Click the Expand Dialog Box button and in the Col_index_num box, type 2 In the Range_Lookup box, type False and click OK.

• Select cell G19 and in the Name Box type Shipping_Code Select cell G42. In the Function Library group, click Lookup & Reference to insert the HLOOKUP function. In the Lookup_value box, type E40 and in the Table_array box, type Shipping_and_Handling_Charges .In the Row_index_num box, type Shipping_Code .Leave the Range_lookup argument blank.

• Click OK, and review the results. The weight for this order is 2.75 pounds. Cost to ship via Priority should be $6.50, which corresponds to the amount shown in cell G7.

• Save the workbook.

Page 12: Name Ranges and LookUp Functions - repo.pmi.edurepo.pmi.edu/online/Master_Documents/CPT301_Microcomputer... · Retrieving Data Using an HLOOKUP Table ... Create a VLOOKUP function

How to Open a Template 12

Selecting All Sheets

Inserting ‘Sheet Name’

Hiding Rows Containing Lookup Tables

Protecting worksheets and cells containing formulas helps prevent a user from accidentally or deliberately changing, moving, or deleting important data • Select rows 3:12 and on the Home tab, in the Cells group, click Format.

From the Visibility section, select Hide & Unhide, and select Hide Rows. Notice the dark border that displays between row 2 and row 13. Click cell A25 and observe that the border is no longer visible.

• Select rows 2:13 and return to the Hide & Unhide section in the Cells group. Select Unhide Rows to display the hidden rows.

• Select the range A3:I12 and in the Clipboard group, click the Cut button. Select the Sheet2 sheet tab and paste the information into cell A3. Adjust column widths, if necessary, to display all data.

• Right-click the Sheet2 sheet tab and select Rename. Name the sheet Reference Tables. Click the Sheet1 sheet tab and rename it Order Form.

• On the Order Form worksheet, select cell A26 and from the list, select Celtic Bookmarks. Look at the formulas in row 26. Because named ranges were used, when the tables were moved to another location the formulas continue to work.

• In the Quantity column, type 12 and check to be sure all formulas are still correct. Notice the formula in cell G19 now references the Reference Tables sheet.

• Click cell G42 and observe the details of the HLOOKUP formula. • Remove the Sheet3 tab by right-clicking it and clicking Delete. • Select the remaining worksheets by right-clicking the Reference Tables

tab and clicking Select All Sheets. • On the Insert tab, in the Text group, select Header & Footer. In the

Navigation group, click Go to Footer. Click the Right Footer area and in the Header & Footer Elements group, select Sheet Name to add the worksheet name. Click a cell above the footer to view the results.

• On the status bar, click Normal and press Ctrl-Home to return to the top of the worksheet. Right-click the Reference Tables tab and click Ungroup Sheets. On the Page Layout tab, in the Page Setup group, click the Orientation button to change the page orientation for this worksheet to Landscape.

• Right-click the Reference Tables tab and click Hide. • Save the workbook.

Page 13: Name Ranges and LookUp Functions - repo.pmi.edurepo.pmi.edu/online/Master_Documents/CPT301_Microcomputer... · Retrieving Data Using an HLOOKUP Table ... Create a VLOOKUP function

How to Open a Template 13

‘Unprotect Sheet’ button

Unlocking Cells for Data Entry and Protecting a Worksheet

• Select the range A25:A26 and D25:D26 and delete the previously entered data. Delete the data in cell G18 also.

• Revise the formulas in cells G19 and G42 using the IFERROR function to remove the error codes.

• Select the entire worksheet by clicking the Select All box or by pressing Ctrl-A.

• On the Home tab, in the Font group, click the Dialog Box Launcher. In the Format Cells dialog box, click the Protection tab and remove the check from the Locked checkbox. Click OK.

• Select cell G19 and the ranges B25:C39 and E25:G43. Lock the cells in these ranges by opening the Format Cells dialog box again and in the Protection tab, place a check in the Locked checkbox. Click OK.

• On the Review tab, in the Changes group, click the Protect sheet button. Look over the options available in the Protect Sheet dialog box. Click OK to accept the default choices. Observe that the Protect Sheet button has converted to Unprotect Sheet.

• Click cell A25 and select Celtic Bookmarks from the list. Press Tab and note that the protected cells are skipped and the next empty cell becomes active. In cell D25, type 15 .

• In cell G18, type Next Day. Observe that all formulas have been calculated and order total is $50.63.

• Select a cell containing a formula and validate the protection feature by attempting to overwrite it.

• Click OK to close the Warning box and save the worksheet.

Page 14: Name Ranges and LookUp Functions - repo.pmi.edurepo.pmi.edu/online/Master_Documents/CPT301_Microcomputer... · Retrieving Data Using an HLOOKUP Table ... Create a VLOOKUP function

How to Open a Template 14

Format Cells Dialog Box

Print Preview

Hiding Formulas in the Worksheet

Protected formulas can still be viewed in the Formula Bar unless they are hidden. • On the Review tab, in the Changes group, click the Unprotect Sheet

button to unprotect the worksheet. • Select cell G19 and the ranges B25:C39 and E25:G43. On the Home tab,

in the Font group, select the Format Cells dialog box and click the Protection tab. Place a check in the Hidden checkbox and click OK.

• Return to the Review tab and in the Changes group, click Protect Sheet. In the Protect Sheet dialog box, click OK. Click any cell containing a formula and note that it is no longer visible in the Formula Bar or in the cell.

• Click cell A26 and select Tote Bag from the list. Add the quantity 25 to cell D27 and press Enter. Observe that the formulas have updated and the shipping costs have increased to $15. The total order cost is now $455.04.

• Save the workbook.

Setting a Print Area

• On the Page Layout tab, in the Page Setup group, click the Dialog Box Launcher. Click the Margins tab and center the page horizontally. Click OK.

• Select the range A15:G43 and from the Page Setup group, click the Print Area button and select Set Print Area.

• Point to Print on the Office menu and click Print Preview. • Click the Close Print Preview button and save the workbook.

If desired, click Quick Print from the Office menu.

Page 15: Name Ranges and LookUp Functions - repo.pmi.edurepo.pmi.edu/online/Master_Documents/CPT301_Microcomputer... · Retrieving Data Using an HLOOKUP Table ... Create a VLOOKUP function

How to Open a Template 15

Print the Entire Workbook

Saving the Order Form as a Template

• Select the ranges A25:A26 and D25:D26, and the cell G18, and delete the data they contain. The form is cleared of data.

• Scroll through the document so that row 15 is the first row to display in the window. Select cell B19.

• From the Office menu, select Save As. In the Save As dialog box, click the Save as type arrow and select Excel Template.

• Save the file as Deni’s_Order_Template_Firstname_Lastname. • Unhide the Reference Tables sheet by right-clicking the Order Form

sheet tab and clicking Unhide. From the Office menu, click the Print button and from the Print what area, select Entire workbook. Preview the workbook to be sure each worksheet prints on a single page. On the Print Preview tab, click Print.

• To print formulas, click the Review tab and in the Changes group, click Unprotect Sheet. Remember to restore the protection to the worksheet and hide the formulas.

• Close the worksheet without saving these final changes and exit Excel.