UCL EDUCATION & INFORMATION SUPPORT DIVISION INFORMATION SYSTEMS Excel 2003 Logic Exercises Document No. IS-021-v2 Content Task 1 - Validation .....................................................................................................................................1 Task 2: Conditional formatting ..............................................................................................................1 Task 3: IF statements ...............................................................................................................................2 Task 4: Statistical IFs ...............................................................................................................................2 Task 5: COUNTIF and SUMIF .................................................................................................................3 Task 6: AND, OR, NOT .............................................................................................................................3 Task 7: Nested IFs .....................................................................................................................................3 Task 8: Lookup ..........................................................................................................................................4 Task 9: Lookup and RANK function .....................................................................................................4 Task 10: HLookup .....................................................................................................................................5 Task 11: VLookup......................................................................................................................................6 Task 12: Additional exercise ..................................................................................................................6 Training files If you wish to attempt the following exercises and you are not using a training account it is necessary to download the training files used in this workbook from the IS Training web site at: www.ucl.ac.uk/is/training/exercises.htm Full instructions on how to do this are provided on this web page. The downloaded files will be copied to a folder on the r:\ drive (unless other wise specified) into the r:\training.dir\excel\more-formulae-functions folder. UCL Information Systems More formulae and functions - Exercises Task 1 - Validation 1. Open the workbook Validation exercise.xls. 2. Set a validation rule in cell A3 to only accept a date after 01/09/2006 (i.e. greater than or equal to). 3. 4. a) Create a message that explains that only a date can be entered in the cell. b) Add a Warning that will appears when incorrect data is entered with the title “Date check” and the message “The date should be after 1 Sept 2006” Make B3 a text cell with a maximum of 50 characters. a) Add an Input message with a title “Course Title” and the message “Abbreviate if necessary - maximum character = 50” b) Set the Error Alert to Stop with a title “Course Title” and the message “Too many characters” Set up a drop down list in cell C3 of 1, 2, or 3. (Key this information into the Source box.) a) 5. Set the Error Alert to Information, with a title “Room number”, and the message “Only use rooms 1, 2, or 3.” Set up a drop down list in cell D3 to refer to the list of trainers in cells P2:P7. Only allow users to select from this list. Put a Stop message with the title “Trainer”, and the message “Please select a trainer from the list offered”. 6. Set a Stop message if there are less than 4, or more than 12 trainees entered in cell E3. a) Enter the following input message “Courses can only be run if there are at least 4 trainees, with a maximum of 12”. b) Put a Stop message with the title “Trainees”, and the message “Must be between 4 and 12”. 7. Enter the following data into row 3: 01/08/2006 "4" Your name 2 Does Excel allow you to enter 01/08/2006? What message did you receive? Could you enter the full course title in cell B3? Abbreviate as below and try again. Was it possible to enter room number 4 in cell C3? Set the room number to Room 1 instead. Was it possible you type in your own name in cell D3? Select any name from the list instead. Was it possible to run the course with 2 participants? Set this figure to 6 instead. 01/08/2006 8. Advanced Excel - Importing data and sharing workbooks Adv Excel - Importing data and sharing workbooks "1" Pravin Saheed 6 Save the workbook as Task 4a.xls and close it. Task 2: Conditional formatting 1. Open the Club.xls workbook. 2. Apply conditional formatting to highlight any members who joined the club after 1990 in blue. UCL Information Systems 1 More formulae and functions - Exercises 3. Apply conditional formatting to highlight members, whose names occur before “R” in the alphabet, using a yellow background for the cells. 4. Check that the conditional formatting has worked, and then save and close the file. 5. Open the Exercise conditional formatting.xls workbook 6. Apply Conditional Formatting to cells B4:M4 in the Total Income row to display, in a blue font, any cells that are less than £1000. 7. In the Total Expenses row (cells B15:M15), apply a background colour to any cells which have a total greater than or equal to £1000. 8. In the Monthly Saving row (cells B16:M16), apply a pattern to indicate all monthly savings above £1000, and also display monthly savings below £500 in a different way. 9. Change the amount in cell J2 to £850.00 and watch to see if the formatting in any of the cells change. 10. Save the workbook as Exercise 3A and close it. Task 3: IF statements The IF Function 9. On a blank workbook, format the cells of column C to currency using the £ symbol. 10. In cell B1 enter the text Calculating Interest. 11. In cell B3 enter the text Balance. 12. In cell B4 enter the text Interest. 13. Enter any figure in cell C3 for your bank balance. 14. The interest will depend on whether your balance is over or under £500. Use the Insert Function to enter the following function in C4: =IF(C3<500, C3*0.05, C3*0.07) 15. The result will depend on the balance you entered in cell C3. Change this balance to £100. The interest should be £5. Change the balance to 1000. The balance should be £70. 16. Save as Exercise3.xls and close the workbook. Task 4: Statistical IFs 1. Open the Ifs and or not.xls workbook. 2. On the Statistical worksheet, name the range E2:E18 “Total”. 3. In cell F2, use the MAX function within an IF statement to find the prize winner (the student with the highest total score). Indicate this by placing the word Prize in the relevant cell. All other cells in the Prize Winner column should remain blank. 4. Save your workbook as Task3.xls and leave it open for the next exercise. More formulae and functions - Exercises 2 UCL Information Systems Task 5: COUNTIF and SUMIF 1. Open the file: pivot.xls. 2. Using the Create Name function, create names for all of the columns in the spreadsheet (you should be able to do this in one simple operation). 3. Create the following text in the respective cells: Females Males Count Total Salary Average Salary I7 I8 J6 K6 L6 4. Use the COUNTIF function to find the numbers of females and males. The formulae should be entered into cells J7 and J8 respectively. (Use names in the formulae instead of ranges.) 5. In cells K7 and K8 use the SUMIF function to calculate the total salaries for females and males respectively. (Use names in the formulae instead of ranges.) 6. In cell L7 and L8 calculate the average salaries for females and males using the values calculated in questions 4 and 5. 7. In cell I10 enter the label High Earners. 8. In cell J10 enter a function to calculate the number of people earning £50,000 or more. Task 6: AND, OR, NOT IFs – AND, OR 1. Open the Ifs and or not.xls workbook. 2. On the And,Or worksheet, name cell F2 “passmark” and F3 “creditmark”. 3. In E2 enter a formula that will check whether each student has failed, passed, or gained a credit. They have failed if only one mark is below 60 (cell F2). They only achieve a credit if all marks are 80 or over (cell F3). Hint: Use the OR function to test for failure. Next, use an AND function to test for the credit rating. Ask your tutor if you need assistance. 4. Paste your formula to cells E3-E6. 5. If you know how to use conditional formatting, use this feature to indicate Fail in red text and indicate Credit with a yellow background and black bold text. (Leave Pass as normal text.) 6. Save your workbook as Task4.xls and close it. Task 7: Nested IFs UCL Information Systems 3 More formulae and functions - Exercises 1. On a blank workbook key in the following column heading in cells A1 - D1: Student Name, Mark, Rating, Target Mark 2. Make columns A and D wider to fit text. 3. Key in student names in A2 - A6: Pamela Smith, Jane Peters, Steve Brown, Jackie Moss, Ron Gold 4. In B2 - B6 key in their exam results: 60, 45, 89, 67, 80 5. In D2 key in the Pass mark of 60 6. In D3 key in the Credit mark of 80 7. In C2 key in the formula to calculate whether they have passed, failed, or gained a credit. Try this for yourself first, but ask if you need help. Hints: Suggest you find who failed first, ie, less than 60, then those with Credit, else Pass. Don't forget to use absolute cell references for D2 and D3. Use, more than or equal to, for the Credit mark. 8. Use AutoFill to copy the formula to cells C3-C6. Check the results. =IF(B2<$D$2, “Fail”, IF(B2>=$D$3, “Credit”, “Pass”)) 9. Save as Exercise4.xls and close the workbook. (You will need this workbook for the next exercise.) Task 8: Lookup 1. Open the workbook Lookups.xls. Today's date can be calculated by using the TODAY() function. Note that this is different to using the shortcut "CTRL+;" in that the date will be updated every time the spreadsheet is refreshed or re-opened. 2. Use the TODAY() function to enter today's date into cell B3 on the LOOKUP worksheet. For any date it is possible to calculate the actual day of the week this fell on. By using the WEEKDAY() function a number between 1 and 7 is returned, where 1 represents Sunday etc. 3. Use the WEEKDAY function to calculate the numerical value of the day of the week in cell B4. This function does not return the name of the day, which may be more user friendly. 4. In cell B16, use the LOOKUP (array) to "look up" the value calculated by the WEEKDAY() function in cell B4 and the data in cells B8:C14 (this range has been named “days”) and return the actual name of the day. 5. Save your workbook as Lookups1.xls. Task 9: Lookup and RANK function 1. With the Lookups1.xls workbook open on your screen, select the Rank worksheet. In this exercise the exam results from a number of students are listed in a column B. The range B5:B21has been named scores. More formulae and functions - Exercises 4 UCL Information Systems A number of prizes are available for the best performing students. By using the RANK() function is possible to calculate the relative position of each student's score, with a value of 1 meaning the highest score in the list etc. 2. Use RANK() to calculate the position of each student, placing the results in the next column to the right of each score (C5:C21). The top 5 students can either choose an actual prize or a cash alternative, all others unfortunately get nothing. The rank, the prizes, and the cash alternatives are all listed in separate tables in the Tables worksheet. 3. Use =LOOKUP(lookup_value,lookup_vector,result_vector) to calculate the cash prize awarded to each student, and place the results in the column next to the rank. The lookup_value is the rank previously calculated, the lookup_vector is the table with the ranks listed is ascending order and the result_vector is the table with the prize. 4. In a similar way determine the alternative prize for each student. (Hint: the result_vector will need to be changed). Note: If LOOKUP can't find the lookup_value, it matches the largest value in lookup_vector that is less than or equal to lookup_value. So in this exercise we had to include a rank of 6 in the lookup_vector with no prizes, so that anyone with a rank of 6 (or greater) would not get any prize.) 5. Save your workbook as Lookups2.xls and close. Task 10: HLookup 1. Open the workbook HLookup.xls. 2. The worksheet consists of a discount calculation at the top and the lookup table at the bottom. The discount available depends directly on the number of items bought. 3. Using the Function Wizard, enter the lookup calculation in cell D8 as follows: a) Select the Hlookup function from the Lookup & Reference category from the Insert Function dialog box. b) The Lookup Value is D4. c) Table array is C18:I19. d) Row index number is 2. e) Leave the Range lookup blank. 4. Excel will look up the value in D4 in the table covering C18:I19, and will return the value in the 2nd row of the table. 5. The value returned is 10%, corresponding to Selling 5 items. Change the Number Bought in D4 to 23. The Discount % changes and so does the Discount Price. 6. As the Range lookup field was left blank, Excel will find the largest value which is less than the lookup value. If you key in FALSE in the Range lookup field, Excel would only look for an exact match, or return as error value of #N/A. 7. Save the workbook as Exercise7.xls and close. UCL Information Systems 5 More formulae and functions - Exercises Task 11: VLookup Vlookup Function 1. Open VLookup.xls and go to the Charges page. 2. Click anywhere in the data and sort column A into ascending alphabetical order. (Remember, the data in the Lookup array must be in ascending order.) 3. Go to the Deliveries page. 4. In cell C2, use the VLookup function to calculate the Delivery charge for each delivery as follows: a) The Lookup value is in column B on the Deliveries worksheet. b) The Table array is on the Charges worksheet. The range A1-C7 has been named 'costs'. c) The column index number is 3 (the Delivery Charge from the Charges worksheet). 5. Copy the result to the rest of column C. 6. In cell D2, calculate the amount spent on petrol for each delivery as follows: a) Use the VLookup function to find the distance to the customer in the same table array as used in question 2 above. b) In the same function, multiply the distance to the customer listed in column B for each delivery by 2 to get the round-trip distance, and then by 0.06 (the average cost that is paid for petrol per km). 7. Save your workbook as Exercise8.xls and close. Task 12: Additional exercise Open the workbook More Lookups.xls This exercise combines the use of conditions and lookup tables to calculate the annual subscriptions required for members of a club. The fees are based on the age of the member as well as if they require a car park space. A table setting out the rates for each age bracket and cost of car park space are listed in a table names rates on the VLOOKUP worksheet. The names of the club members, their ages and their desire for a car park space (Y/N) are listed in a separate table. 1. Using the LOOKUP() function to lookup each person's age in cells B4:B7, and return the age bracket as a text string (from A4:A7) in the column labelled Age Bracket (cells D14:D19). Remember to make the range references absolute, or name the ranges. 2. Use the VLOOKUP() function to look up each person's age in the range named rates (B4:D7), and return the basic annual fees (column 2). 3. Use the IF() function and VLOOKUP() to look up the cost of a car park space only if the person wants one (i.e. there is a Y in the Use of Car Park? column), else return a value of zero. 4. Calculate the total fees by adding up the two columns. More formulae and functions - Exercises 6 UCL Information Systems 5. Save your workbook as Exercise9.xls and close it. UCL Information Systems 7 More formulae and functions - Exercises