IT Training Excel: Further Functions Jane Barrett, IT Training & Engagement Team Information System Services Version 4.1
Scope Learning outcomes Understand basic cell manipulation using formulas and formatting of data. Explore the scope of functions that are available within Excel and how they can be used. Gain an understanding and experience of how to create your own functions. Table of Contents Scope... 2 Table of Contents... 2 Introduction... 3 Cell manipulation... 3 Calculations... 3 Copying formulae... 3 Paste special... 4 Common Functions... 5 Using functions... 6 Use common functions with Formula AutoComplete... 8 Use the IF logic function... 9 Use SUMIF and COUNTIF to create conditional totals... 11 Using Logical Functions AND or OR... 12 Understanding Date Serial Numbers... 13 Understanding common date functions... 14 Using the DATEDIF function... 16 Using date offsets for managing schedules... 16 Concatenating Strings... 17 Using the LEFT, RIGHT and MID functions with fixed strings... 18 Using FIND and LEN functions with delimited strings... 19 Formatting data... 21 Name cell range(s) in a worksheet... 21 Create custom number formats... 22 VLOOKUP functions... 23 Using a VLOOKUP function for an exact lookup... 23 Using a VLOOKUP function for an inexact lookup... 25 Macros... 26 Record a simple macro (e.g. page setup changes)... 26 Run a macro... 26 Assign a macro to a custom button on a toolbar... 26 Contacts... 27 For queries or help... 27 Useful resources... 27 Training videos... 27 Booking other Excel Courses... 27 Online training materials from Microsoft... 27 Your feedback... 27 Help us improve your training... 27
Introduction This course will explain how you can get the most out of spread sheets and how you can use functions to get the best out of your data to produce intelligent output. You will learn the various different types of functions that are available and how they can be used to make your worksheets more efficient. By the end of this course you will feel confident in using the functions available and increase your knowledge of the other possibilities that Excel can offer you. How this course has changed over time, What the standard installation is on machines. Cell manipulation Calculations If you wish a cell to contain the result of some calculation then start the cell contents with =. For example =23*34 (Figure 1) or =b1/10 if the contents of cell b1 divided by 10 (Figure 2). Figure 1 Figure 2 Note the result of the calculation is shown in the worksheet, but if you select the cell the formula appears in the editing box. Note that it is possible to show formula in cells by selecting the Show Formula button from the Formula ribbon tab. If a formula is used, the changes in the values of any cells referred to instantly change the displayed value. Copying formulae When you copy a formula from one cell to a range of cells by using the extend button Excel makes suitable changes to the formula. For example, consider the Figure 3, 4 and 5. Following values in column C are found by multiplying column A by column B. Therefore in cell C2 enter the formula =a2*b2, select this and extend it down to cover cells C3 to C6. The result is shown in the column C shown on the right hand screen. Notice that the formula has been suitably changed as it extended down. To calculate a total in cell B7 you could enter the formula =b2+b3+b4+b5+b6 or better still use the SUM function which in this case is =SUM(b2:b6) (see section on functions below). Extending this sideways into cell C7 (yielding =SUM(c2:c6)) gives a total for column C. 3
Now consider adding a column D showing the values in column C as a fraction of the total (in C7): Enter formula in cell C2 Extend the selection Result Figure 3 Figure 4 Figure 5 To cause Excel not to automatically change any part of an address when extending a selection you prefix any element of the address with a $ symbol. There are four possibilities: A3 a general cell reference. $A3 always look in column A but vary the row number. A$3 - always look in row 3 but vary the column letter. $A$3 Fix both column letter and row number (always refer to this specific cell). When you extend cell C1 You get (A$1 has remained unchanged) Paste special Figure 6 Figure 7 When you copy cells you sometimes need to paste the numbers showing in cells rather than the underlying calculations that resulted in those values. To do this use Paste Special and choose the required option: Figure 8 Figure 9 4
Task 1 Using the sheet Week 1: 1. Enter in cell H2 a formula for the total of John s values. 2. Copy this formula to obtain totals for the other 4 people. 3. In cell B10 enter a value for the total of all values from week 1. Using the sheet Week 2: 4. Complete the sheet using formulas in the same way as Week 1. Using the sheet Totals: 5. Enter a formula in cell B2 to show the total of John s Monday values over weeks 1 and 2. 6. Extend this to get totals for each day and person. 7. In cells C13 to C17 enter formulae to return the full name. (Don t forget the space). 8. Paste the results into cells A2 to A6. Common Functions Task End There are a wide range of functions available to aid calculations, or perform other tasks. To access the various Functions available click on the fx button the editing tool bar. You will be presented with a dialogue box that helps find the required function. Figure 10 Example: I have a large class of students, and their exam marks and need to decide who has passed and who has failed. Select Logical functions, then select IF Enter the required data 5
Click OK and then extend the selection cells C3 to C8. And the result is: Using functions All functions are initiated by starting in the cell you want the function to be in and then clicking on fx (or typing the function in if you know the syntax). Excel responds with a function wizard to help you fill in the parameters. These can be values, cell references, ranges or nothing as appropriate. Below is a summary of all the main functions: Date and time functions Function Purpose Parameters Example TODAY Returns today s date no parameters =today() DAY Returns the day part of a date the date =day( 5-Apr-03 ) (gives 5) MONTH Returns the month part of a date the date =month( 5-Apr-03 ) (gives 4) YEAR. Returns the year part of a date the date =year( 5-Apr-03 ) (gives 3) Mathematical functions Function Purpose Parameters Example SUM Sums a group of numbers range, or list of numbers =sum(a1,a3,a5) =sum(a1:a20) =sum(namedrange) AVERAGE Averages a group of range, or list of numbers =average(a1:a20) SUMIF SUMIFPOSITIVE ROUND INT numbers Sums a group of numbers in one range if the corresponding value in another (or the same) range meets a certain condition not available in EXCEL, use SUMIF with criteria >=0 Rounds a number to a specified number of digits Round to nearest integer below range containing values to be compared; criteria; range containing numbers to be summed. Number to be rounded Number of digits If num_digits is greater than 0, then number is rounded to the specified number of decimal places. If num_digits is 0, then number is rounded to the nearest integer. If num_digits is less than 0, then number is rounded to the left of the decimal point. number to be rounded =sumif(b1:b20,">5",a1:a20) Adds those numbers in cells a1 to a20 where the value in the b column is greater than 5 =ROUND(2.149, 1) Rounds 2.149 to one decimal place (2.1) =ROUND(-1.475, 2) Rounds -1.475 to two decimal places (-1.48) =ROUND(21.5, -1) Rounds 21.5 to one decimal place to the left of the decimal point (20) 6
Use statistical functions Function Purpose Parameters Example COUNT Counts the number of cells in a range of numbers =count(a1:a20) range which contain numbers COUNTA Counts the number of cells in a range of numbers =counta(a1:a20) range which are not blank COUNTIF Counts the number of cells within a range that meet the given criteria range of numbers criteria =countif(a1:a20, >5 ) Use text functions Function Purpose Parameters Example PROPER Capitalises the first letter of each word in the text text =proper( jerry mouse ) gives Jerry Mouse UPPER Capitalises every letter of the text text =upper( jerry mouse ) gives JERRY MOUSE LOWER Decapitalises every letter of the text text =lower( JERRY MOUSE ) gives jerry mouse CONCATENATE Joins the parameters into one test stream. NOTE this can be replaced by the & operator text to be joined =concatenate(a1,b1) joins the vales of cells a1 and b1 together. Use lookup and reference functions Function Purpose Parameters Example HLOOKUP Searches for a value in the top row of a table or an array of values, and then returns a value in the same column from a row you specify in the table or array. value, table, row, exact see Excel Help VLOOKUP Use logical functions Searches for a value in the leftmost column of a table, and then returns a value in the same row from a column you specify in the table. value, table, col, exact Function Purpose Parameters Example IF Returns one value if a condition condition if(a1>10, Big, Little ) you specify evaluates to TRUE and another value if it evaluates to FALSE value if true value if false AND Returns TRUE if all its arguments list of conditions and( a1>5, b7<9 ) are TRUE; returns FALSE if one or more argument is FALSE OR Returns TRUE if any argument is list of conditions or( a1>5, b7<9 ) TRUE; returns FALSE if all arguments are FALSE ISERROR Returns true if cell displays an error message for example #VALUE! see also other IS functions cell reference 7
Use database functions (see also section on data handling above) Function Purpose Parameters Example DSUM Adds the numbers in a column of a list or See EXCEL help for more details database that match conditions you specify DMIN Returns the minimum value from selected database entries DMAX Returns the maximum value from selected database entries DCOUNT Counts the cells that contain numbers in a column of a list or database that match conditions you specify Use common functions with Formula AutoComplete The functions most often seen in workbooks are SUM, AVERAGE, COUNT, MAX and MIN. An easy way to enter these functions is by using the AutoComplete feature. 1. Click on the sheet Tallest Buildings. This sheet contains information about the world s tallest buildings and we are going to use functions to summarise the data. 2. Click into cell B25 and type =s into the cell. A list drops down and shows every function beginning with s this is the AutoComplete feature. 3. Continue typing SU and now the list only shows functions beginning with SU. You can now either click on the word SUM or use the down arrow to select it. 4. The SUM function now displays a tip telling you what the function does: 5. To Display detailed help for the SUM function press the F1 key whilst SUM is still highlighted in the dropdown list. Read the help if you are interested and then close the help window. 8
6. Complete the formula so that you see =SUM( a small box appears beneath the function telling you the syntax for the function: The syntax tells you what parameters or arguments you need to include with a round bracket whilst square brackets denote optional parameters. 7. Select the cells that you need to sum (cells F4:F24) with the keyboard or the mouse and press Enter to complete the formula. 8. Now use the same technique to add MAX, MIN, AVERAGE and COUNT functions to cells B27:29. Use the IF logic function The IF function is one of Excel s most useful functions, however it often causes confusion because people don t understand the concept of a logical test. A logical test requires a question that can be answered True or False. If the answer is True one action is taken or a different action is performed if False. Here are some examples of a logical test: Expression Returns Why? 6=2 False Because 6 does not equal 2 100<90 False Because 100 is not less than 90 6+2 = 4+4 True Because 8 does equal 8 In this example we will use three different logical tests to calculate several employees earnings during the week. 1. Click on the Earnings Summary sheet and notice the payroll rules section: Logical tests will be constructed to calculate Standard Pay, Overtime Pay and Bonus. 9
In the case of Standard Pay, the logical test will be, Did this employee work less than or equal to 35 hours this week? The formula for the logical test is E9<=35, if this returns TRUE then the standard pay will be: Hours worked * Hourly rate, or (E9 * D9), because the employee worked for 35 hours or less. If this returns FALSE, then the standard pay will be: 35 * Hourly rate, or (35 * D9), because the employee worked more than 35 hours. 2. Use an IF function to calculate standard pay, Click in cell F9 then click on the fx button. When the wizard pops up select Logical from the drop down and IF from the window below. The Functions Arguments dialog appears, complete it as follows: Click OK and the standard pay should now be correctly displayed in cell F9 (525.00). 3. Now we will use an IF function to calculate overtime pay. Using the rules you should now have a good idea how to calculate the overtime pay. The correct arguments for the IF function should be: 4. Use the IF function to calculate a bonus. The arguments will be: 5. Add a formula to cell I9 to calculate total pay, you can use the SUM function you learnt earlier. 10
6. AutoFill the formulas in cells F9:I9 to cells F10:I17. Your payroll worksheet should now be complete and look like this: Use SUMIF and COUNTIF to create conditional totals Whilst the IF function returns a TRUE and FALSE result the SUMIF and COUNTIF functions are used to sum or count values within a range based on a similar logical test. 1. Click on the sheet Headcount & Salaries, we will use SUMIF and COUNTIF to list the total salary and headcount for each gender. 2. Click into cell B21 and then fx, select Math & Trig SUMIF. The function dialogue box appears. There are three arguments for the SUMIF function; The Range argument defines the range of cells in which to look for the department name, (in this case Sales). This will be D4:D17. The Criteria argument is the thing to look for within the stated range. In this case it is the word Sales contained in cell A21. The Sum-range argument is the range containing numerical data that needs to be added up when the criteria is true. In this case, it is the range C4:C17. Complete the dialogue with the following arguments: Note the use of absolute references for each range, which will allow for the Auto Fill for the Purchasing and Logistics totals. Click OK to complete the function, then auto fill down. 11
3. Use the COUNTIF function to calculate the headcount for the department. COUNTIF works in exactly the same way as SUMIF but returns a count of all cells that match the criteria. Click in cell C21, and then Click: fx Statistical COUNTIF Complete the dialogue with the following arguments: Click OK and then auto fill cell C21 to cells C22:C23 to display the headcount for Purchasing and Logistics. 4. Use a SUMIF and COUNTIF function to calculate the salary for male and female employees in cells B27:C28. Use exactly the same technique as you did for Salary and Headcount by Department. The correct arguments are: Using Logical Functions AND or OR Previously we used the IF function to return a TRUE and FALSE result depending on a logical test. Now we will use two more logical tests called AND and OR to create more complex Boolean criteria. The example for this exercise computes bonuses for employees based upon the following rules: Here are the bonus figures for the first three employees: Johnny Cain exceeded his target but received no bonus because he only has two years service. George Marley has over five years service so receives his bonus even though he didn t reach his sales target. Betty Anan has three years service and she has exceeded her target, so she gets her bonus. 12
Another way of expressing the logical test that governs when the bonus is paid is: If Sales > Target AND Years Service >2 OR Years Service >5 Excel can implement these rules using the AND and OR functions by creating the following logical tests, firstly to see if Johnny Caine s sales are above target: =AND(C10>D10, B10>2) The AND function will only return TRUE if both expressions evaluate True. We also need to check if the employee has over five years of service: =OR(B10>5, AND(C10>D10, B10>2)) The OR function will return TRUE is either of the arguments return True. Now let s put it into practice, select the Bonus sheet from the workbook. 1. Click in cell E10 then Click fx Logical IF 2. Enter the following values into the dialogue box, (the logical test is the same as above): 3. Auto fill the formula from E10 to the end of the range. Understanding Date Serial Numbers To do any calculations in Excel involving dates it is useful to understand date serial numbers. Dates are stored as simple numbers which contain the number of days that have elapsed since 1 st January 1900, as a result Excel has difficulty working with dates before this time. 13
In Excel, every time is a date and every date is a time, for example 1 st January 1900 is represented by 1 and the 5 th January 1900 is stored as the number 5. The number 5.5 would mean midday on the 5 th January 1900. 1. Turn to the sheet called Date. Column B is an exact copy of column A, now format column A to be shown as a date: 2. Set a custom format of dd/mm/yyyy hh:mm for the dates in column A to show both dates and times. 3. Change the time in cell A2 to 12.00 and you will notice that the number in B2 has now changed to 2.5 showing that times are stored by Excel as the decimal part of the number. 4. To work out the number of days that occurred between 01/01/1900 and 01/01/2000, just enter the two dates into cells A7 and A8. Next apply the comma style to cell A9 then subtract one date from the other by entering the formula =A8-A7 into cell A9. You should find that 36,525 days occurred during the last millennium. Understanding common date functions Now you have a good understanding of how Excel stores dates as serial numbers you can begin to use this knowledge with Excel s primary date functions, TODAY, DAY, MONTH and YEAR. 1. Turn to the sheet called Resources. This worksheet contains a list of employees along with their dates of birth. 2. Use the YEAR function to calculate the year in which each employee was born. 14
3. Click in cell D4. Click on fx then select Date & Time Year, this will bring up the arguments dialogue box. 4. Click cell C4, because you know that all dates are represented by a serial number, and because cell C4 contains a date, this reference will cause the YEAR function to return 1965. Notice that the dialogue previews the result as =1965 and also lets you know the serial number for 15 th April 1965 is 23,847. Click OK 5. Use the DAY function in the same way to place the day in cell E4 6. Now do the same with the MONTH function into cell F4. 7. Use the TODAY function to place a volatile current date into cell G4. This function returns the current date so changes from day to day. 8. Use the YEAR function to place the current year into cell H4. As this cell relates directly to the volatile current date it will also change. 9. Add a formula to cell I4 to calculate the employee s maximum age this year by simply subtracting their max age this year from the year born. Now auto fill the rest of the columns to complete the sheet. 15
Using the DATEDIF function One of the most useful date related functions in Excel is the DATEDIF function. However if you try to find it using the fx button you will be unsuccessful, it appears to be one of Excel s little secrets. DATEDIF is able to calculate the difference between two dates for several intervals and the syntax for the function is =DATEDIF(StartDate, EndDate, Interval) StartDate The first date EndDate The second date Interval The interval to return, such as the number of months or years between 2 dates The interval arguments are: m Months between two dates d Days between two dates y Years between two dates ym Months between two dates, ignoring the year md Days between two dates, ignoring the months and years. 1. Turn to the sheet called Resources (2). This worksheet contains the same list of employees along with their dates of birth but now we will calculate their age using DATEDIF. 2. Add the following formula to cell I4: =DATEDIF(C4,TODAY(), y ) This function works by comparing the date of birth, (in cell C4) with today s date, (returned by the TODAY function) and returns the intervals in years. 3. Now using the same technique, calculate each person s precise age in years, months and days in the remaining columns. Using date offsets for managing schedules Excel s date function can be used in a number of ways to dynamically manage date offsets. For example if a service scheduler required that vehicles be inspected 20 days after first supply, 3 months after the 20 day inspection and then every year thereafter we could make a spread sheet to help us with this task. 1. Turn to the sheet called Service Schedule. 16
2. Put a formula into cell B4 that will calculate the date for the 20 day inspection based upon the date in cell A4. Type =D into cell B4, the DATE function will be the first to appear, press TAB key to enter the formula into the cell. Click the fx button The function arguments dialog is displayed and requires three numerical arguments, so we will use the YEAR, MONTH and DAY functions to convert each part of the date into numbers. Note that in the Day argument, the number 20 has been added to create a date 20 days later than the date in cell A4. Click OK. 3. Using the same technique now complete the table by entering appropriate formulas into cells C4 and D4. Use auto fill to copy the formula to the remaining cells. Concatenating Strings In the world of computers, letters, numbers, spaces, punctuation marks and other symbols are referred to as characters. When several characters are grouped together they are called a string, e.g. ABC123, John Smith. Strings may be of any length, from a single character to thousands of words. The CONCATENATE function can be used to join strings together using the & symbol. You may wish to concatenate, salutation, first and last names; = Mr & John & Smith would give MrJohnSmith If you want spaces between the words, they also have to be added; = Mr & & John & & Smith would give Mr John Smith Using the fx button brings up the arguments dialogue which makes it a lot easier. 1. Turn to the sheet called Watches. This worksheet contains a list of details about classic watches and their selling price. Your task is to concatenate the detail into a classified ad in cell F8. 2. Click in cell F8 then Click fx Text Concatenate 3. The format of your ad will be Description, (Date), - Selling Price. 17
4. Auto fill the remaining cells. You may notice that the price now shows as a number without the correct formatting, 16430 instead of 16,430. This is because Excel sees this value as a number so we have to convert it to a string as well. 5. Click in cell F8 then click the fx button. The dialogue window will reappear, change text 4 & 5 to what is shown below, click OK and view the result: Using the LEFT, RIGHT and MID functions with fixed strings Sometimes data may be contained in one long string but parts of the data may have different meanings e.g. a post code or a number plate. The LEFT, RIGHT and MID functions can be used to extract which bits of the data we need so that we may use the information elsewhere in the spread sheet. 1. Turn to the sheet called Books. This worksheet lists some of the bestselling books of all time along with their ISBN number. ISBN numbers are a good example of a fixed width string which contain four distinct pieces of data: 2. First we will extract the EAN from the ISBN code using the LEFT function, which takes a given number of digits from the left part of the string. Click in cell F4. Click on fx then select Text Left, then complete the dialogue as follows: Click OK and the EAN is now extracted into F4 3. Now use the RIGHT function to extract the check digit from the ISBN code into cell I4. 4. To extract the Group from the ISBN code using the MID function we know that the group identifier is digit four, but because the ISBN has a dash between the third and fourth digits we ll have to extract a single character from position five in the string. Click in cell G4. Click on fx then select Text MID, then complete the dialogue as follows: 18
5. Now use a MID function to extract the Publisher and Title code from the ISBN into the appropriate columns. 6. Now auto fill and complete the table. Using FIND and LEN functions with delimited strings The LEFT, RIGHT and MID functions worked well with ISBN because the number is a fixed length with the data always appearing in the same place in any number. However often life is not that simple or organised! For example here are two international telephone numbers: +44 (0)113-4960227 (a UK telephone number) +356 (0)2138-3393 (a Maltese telephone number) The country code (or international dialling code) is shown as a + symbol followed by one or more numbers. The NDD (National Direct Dialling prefix) is shown in brackets. This is the access code used to make a call within the relevant country but is omitted when calling from the outside of the country. The Area code consists of the numbers after the closing bracket but before the hyphen. 1. Turn to the sheet called Phonebook. Now we know how the number is structured we can use the FIND and LEN functions in combination with the MID function to extract the country code, NDD and phone number from an international number. 2. Insert a FIND function into cell C4 to find the first occurrence of an opening bracket within the telephone number. Click in cell C4. Click on fx then select Text Find The FIND function demands three arguments. The first is the character to find, (in this case the opening bracket), the second is the text to search within, (in this case the telephone number in cell B4). There s also an optional argument that allows you to begin the search at a specified position within the string. Complete the dialogue as follows, (just put in the open bracket and Excel will add the quotes for you): 3. Now insert a FIND function into cell D4 and use the same technique to find the closing bracket. 4. Insert a FIND function into cell E4 to find the first occurrence of a hyphen within the telephone number. 5. Insert a LEN function into cell F4 to find the total numbers of characters in the telephone number Click in cell F4. Click on fx then select Text Len, click in cell B4 and OK 19
6. Insert a LEFT function into cell G4 to extract the country code. Note that C4-1 is used for the number of characters to avoid returning the open bracket. 7. Insert a MID function into cell H4 to extract the area code. 8. Insert a MID function into cell I4 to extract the phone number. 9. Auto fill the spread sheet to complete the task. Using the Sheet Functions, practice what you have learnt and try to complete the tasks given below: Task 2 1. Enter in Cell C3 today s date. 2. Enter in cells C4 to E4 the day, month and year of C3. 3. In C5 the sum of the value column (H), In D5 the average. 4. In C6 the sum of the values of type A, in D6 type B. 5. In C7, how many cells in G1:H21 contain numbers. 6. In C8, how many cells in D1:E10 are blank. 7. In C9, how many negative numbers in value column. 8. In C10 & D10 properly capitalised E10 & F10. 9. In column I write a formula to put in Positive or Negative depending on the value of the number in H. Task End 20
Formatting data Covers: Name cell range(s) in a worksheet; Apply automatic formatting to a cell range; Create custom number formats; Use conditional formatting options; Use paste special options; Import a text file delimited by comma, space or tab. Name cell range(s) in a worksheet 1. Select the range you wish to name: In this example B3:D6. 2. Type the name of the range in the name box and press Enter: In this example myrange. Name Box Figure 14 This name can then be used in place of the definition wherever required. For example in Figure 15, cell A9 contains the formula =SUM(myrange) which is equivalent to =SUM(B3:D6). Name a 3D cell range over several worksheets Figure 15 1. On the Formulas tab, in the Defined Names, then click Define Name. 2. In the Names box, type the name. (It must not contain any spaces and it should begin with a letter). 3. If the Refers to box contains a reference, delete it. 4. In the Refers to box, type = (equal sign). 5. Click the tab for the first worksheet to be referenced. 6. Hold down SHIFT and click the tab for the last worksheet to be referenced. 7. Select the cell or range of cells to be referenced. The result should look something like this =Sheet1:Sheet3!$A$14:$C$18. The format for referring to a cell on a specific sheet is sheetname!cellreference eg sheet1!a3. The format for referring to a range of one cell over several sheets is startsheetname:endsheetname!cellreference eg sheet1:sheet4!t6. 21
Create custom number formats 1. Select the range to be formatted. 2. On the Home tab, in the Cells section expand the Format list and choose Format Cells. 3. Choose the Number tab and select Custom from the Categories list. 4. Enter your formatting code. 5. Codes for numbers are form with a combination of #, 0, and? symbols. # displays only significant digits and does not display insignificant zeros. 0 (zero) displays insignificant zeros if a number has fewer digits than there are zeros in the format.? adds spaces for insignificant zeros on either side of the decimal point so that decimal points align when formatted with a fixed-width font, such as Courier New. You can also use? for fractions that have varying numbers of digits. To display Use this code 1234.59 as 1234.6 ####.# 8.9 as 8.900 #.000 631 as 0.6 0.# 12 as 12.0 and 1234.568 as 1234.57 #.0# 44.398, 102.65, and 2.8 with aligned decimals???.??? 5.25 as 5 1/4 and 5.3 as 5 3/10, with aligned division symbols #???/??? Thousands separator To display a comma as a thousands separator, or to scale a number by a multiple of one thousand, include a comma in the number format. To display 12000 as 12,000 #,### 12000 as 12 #, 12200000 as 12.2 0.0,, Use this code Using Sheet Format: 1. In table 1 format the values according to the column heading. 2. Format the dates in column I to match the form in column H. Task 3 Task End 22
VLOOKUP functions Using a VLOOKUP function for an exact lookup The VLOOKUP function enables data to be found within a table or list based on a unique identifier. For example a retailer has created a stock code to save time when creating invoices. The code is made up of the first two letters of the watch description along with the last two numbers of the date of manufacture. When provided with a stock code, the VLOOKUP function can scan all of the codes in column A until a match is found and then return a value for the same row for any of the other columns. This example will show how to create a VLOOKUP that will automatically return the description of any watch into column B on the invoice then the user enters a stock number into column A 1. First we will insert a VLOOKUP function into cell B6 on the Invoice worksheet to find the description to match the Code in cell A6. On the Invoices sheet, Click in cell B6. fx then select Lookup & Reference VLOOKUP The VLOOKUP function arguments dialog appears. It can be seen that it has three required arguments, (shown in bold), and one optional argument. 2. Add the Lookup_value argument. This is the cell on the Invoice worksheet that provides the value to be searched for in column A of the Stock worksheet. We want to look up the description of the watch with the code CA74. This is contained in cell A6. 23
3. Add the Table_array argument. This is the location of the table or array where we are going to search for a match to the value in cell A6. VLOOKUP always searches the left-most column of the range, table or name. The array on the Stock sheet has already been formatted as a table and been called Stock, so just enter the word Stock into the Table_array argument. Note a table in this instance is better than an array as it is dynamic. This means when extra rows are added the VLOOKUP will include these in its search. An array is static and new items may be added but will not be included in the search unless you specify a new array area for the VLOOKUP. 4. Add the Col_index_num argument. Counting from left to right, this is the column that contains the value we want to return. In this case the description column which is column 2. 5. Add the Range_lookup argument. Although this is optional it is very important as if it is left blank VLOOKUP may return an inexact match, in some cases this may be useful but for the moment we want an error to be returned if a stock code is not found. So set this argument to FALSE. 6. Click OK and Auto fill down, you may notice a problem and this will be addressed next. This function works well when all three lines are populated, but a blank line produces a #N/A error message. We can suppress this with an IFERROR function to return a blank space when an error is encountered. 7. Wrap each VLOOKUP function with an IFERROR function to return a value of your choice, (in this case a blank space) whenever a function returns an error. Click in cell B6 on the Invoice sheet and then look in the formula bar: This is the VLOOKUP that returns the description. We re going to use this formula as the value argument for the IFERROR function. When one function is used inside another function in this way, we sometimes refer to the outside function as a wrapper. 24
Click just to the right of the equals sign in the formula bar and type IFERROR( Notice the tip has appeared. The entire VLOOKUP function is now being used as the value argument for the IFERROR function. To complete the argument click to the extreme right of the formula and add in,, ). The comma tells the function what to do if an error is returned, in this case the two quotes, ( ) tells the function to return an empty string to the cell. Press the Enter key to complete the formula. 8. Now Auto fill the formulas again, the #N/A has been replaced with a blank space. 9. Now try to make a VLOOKUP to fill the Price column, C6:C8 using the skills you have just learnt. Using a VLOOKUP function for an inexact lookup Previously we used the VLOOKUP to search for an exact lookup, setting the fourth argument to FALSE in order to achieve an exact match. However sometimes you don t want to search for an exact match but the nearest match. This is called an inexact lookup. An example of this would be using an exact VLOOKUP for exam grades. If we looked for an exact mark of 80% it would correctly return a grade of A. However a student with a mark of 77% would result in an error as there in no exact mark of 77% in column E. If we ask VLOOKUP to perform an inexact lookup, it will return an exact match if one is found. If an exact match is not found, it will return the largest value that is less than the lookup value. Therefore for VLOOKUP to work with inexact matches, it is vital that the lookup column is sorted in ascending order (from lowest to highest value). E.g. 68% would find row 5 (a grade C) because 60% is the largest value that is less than 68%. 1. Open the sheet called Results. 2. Convert the grades to a table, highlight E3 to F8, Click Insert Table OK 3. Set table styles Light. You have now created a dynamic table. 4. Give the table the name Grades, 5. Now create a VLOOKUP in cell C4 to return the grade in exactly the same way as the previous exercise, except enter the Range_lookup argument as TRUE. 6. Auto fill the cells to complete the sheet. 25
Macros Have you ever spent too much time on a repetitive task in a Microsoft Office program, suspecting that there must be a better way? Perhaps you needed to reformat multiple tables in a long Word document or reorganize data in an Excel worksheet. Or maybe you wanted to make the same changes to several similar Visio pages or PowerPoint slides. If these or similar tasks are familiar, then you need to know about macros. You have probably seen macro warnings when opening Office documents, and so macros make you think of scary terms such as virus or programming. Well, you should know that most macros are not only harmless but they can be tremendous timesavers. And, macros are easier to create and use than you might expect. Record a simple macro (e.g. page setup changes) 1. Choose View, Macros, Record Macro. 2. Give the Macro a name. 3. Perform the actions required. 4. Choose View, Macros, Stop Recording. Run a macro 1. Choose View, Macros, View Macros. 2. Choose the required Macro and click Run. Assign a macro to a custom button on a toolbar 1. From the Office Button choose Excel Options. 2. Select Customize. 3. From Choose commands from select Macros. 4. Select your macro and press Add. 5. Select Modify. 6. Choose an appropriate icon. Select OK. 7. Select OK. 1. Create a Macro to change the layout to landscape and the paper size to A3 2. Assign this macro to the tool bar. Task 4 Task End 26
Contacts For queries or help e-mail: desk@essex.ac.uk helpdesk in first instance. if you are trying to work out what course may be right for you or your team ittraining@essex.ac.uk. Useful resources Training videos http://www.youtube.com/uniessexit Booking other Excel Courses www.essex.ac.uk/it/training/courses/excel.aspx Online training materials from Microsoft http://office.microsoft.com/en-au/excel-help/ Your feedback Help us improve your training Your feedback is important to us. You will receive an e-mail asking you to complete an online feedback survey. Please take a few minutes to tell us what you think. 27