Functions C
Functions C
Nested Functions
Click on the File tab, then choose Save As. Save the file to your computer as “Assignment
8.[Your Last Name].xlsx”, but do not upload it yet!
FYI - You can't always nest one function inside another - for example, you can't use the logical
functions in SUMIF() or COUNTIF().
In the assignment 7 file, you could not type ‘=countif(C2:C61,NOT("food"))’ for you would
get an incorrect result, but you could use the not equal (<>) mathematical operator; you could
type ‘=countif(C2:C61,<>("food"))’ and that would return a valid answer.
To learn more about nesting IF with Logical Functions, watch the first half of the
lecture video.
In cases where nesting is not allowed (or becomes too complex so that it's difficult to
understand what's going on), you may need to carry out the calculations in two stages.
We learned how to get answers based on multiple conditions using SUMIFS and COUNTIFS.
Another way to get answers based on multiple conditions is to use filters and the SUBTOTAL
function.
1. Open the exceldata.xlsx file, found in Canvas.
2. Click on the Accounts tab.
3. Freeze the top row.
4. Click on cell A2.
5. From the Data tab, in the Sort & Filter area, choose Filter.
6. Using the pulldown in cell C1, make the only selected choice ‘Stationery’ and click [OK].
7. Click in cell D62.
8. Click on the [AutoSum] button in the Home tab.
9. Notice that it does not enter a SUM calculation, but a SUBTOTAL. Press [Enter] to
accept the SUBTOTAL function.
10. Using the pulldown in cell B1, make the only selected choice ‘Sarah’ and click [OK].
11. Open your Assignment 8.[Your Last Name].xlsx file that you saved earlier.
12. Going back to the exceldata.xlsx file, right click on the Accounts tab and choose ‘Move
or Copy’.
13. In the Move or Copy dialog box, use the pulldown at the top for “To Book:” and select
the Assignment 8 file from the list.
14. Make sure the ‘Create a Copy’ box is checked and highlight ‘(move to end)’.
15. Click [OK].
The SUBTOTAL function can also give you other measurements (e.g. AVERAGE):
In your exceldata.xlsx worksheet:
With D62 the active cell, click on [Insert Function]
You see the listed Function_num is 9. Click on the ‘Help on this function’ hyperlink.
You'll discover that if the Function_num is 1 (or 101) then you get AVERAGE. A value
of 2 (or 102) is COUNT, 3 is COUNTA, 4 is MAX and 5 is MIN, while the remaining
values are for more complicated statistical functions. Click [Cancel].
Save your file, but leave it open – we still haven’t finished with it yet!
Mathematical Functions
All the functions you met in your math and statistics classes are provided in Excel – SQRT(),
LOG(), EXP(), SIN() etc. - plus many more.
You may have noticed that each time you add a new calculation, the random numbers change.
The same happens if you press [F9] - try it, if you like.
Note** You can change automatic to manual calculation in the Calculation Options area of the
Formulas settings in the Options menu from the File tab.
Dates and times are stored simply as numbers in Excel. The date or time actually appears only
because a special display format is used.
We discussed dates and times, but here’s a reminder of a few examples:
TODAY gives you the current date
NOW gives you the current date and time
YEAR, MONTH, DAY, HOUR, MINUTE and SECOND give you the current
equivalent values
7. Click in cell B1 and type =today() then press [Enter] - today's date appears.
8. In B2 type =now() then press [Enter] - you get both the date and time.
9. To get just the time, in B3 type =now() and press [Ctrl Enter] then click on the
[Number Format] button in the Number group on the Home tab and choose Time –
use the default type selection.
10. In cell B4 press [Ctrl-;].
11. In cell B5 press [Ctrl-:] (aka Ctrl-Shift-;).
Note** The easiest way to enter today's date into a cell is to press [Ctrl-;]. Similarly, [Ctrl-:]
gives you the current time. Note, however, that when you use these, the values are fixed and
are not recalculated when you open the file.
Text Functions
There are also several useful functions for use with text:
LEN counts the number of characters (including spaces) in the text
FIND gives the position of the specified text in the text being searched
LEFT, MID, RIGHT let you select part of the text from the left, middle or right
LOWER, UPPER, PROPER change case (lowercase, uppercase, mixed case)
EXACT compares the contents of two cells to see if they are exactly the same
15. In cell C1 type your name (eg John Smith) then press [Enter]
16. In C2 type =len(c1) then press [Enter] - this counts the letters (+ spaces) in your
name
17. In C3 type =find(" ",c1,1) then press [Enter] - this works out where the space is in
your name.
18. In C4 type =left(c1,c3-1) then press [Enter] - this gives you just your first name
19. In C5 type =right(c1,c2-c3) then press [Enter] - this gives you the rest of your
name
20. In C6 type =upper(c1) then press [Enter] - your name is in capitals
21. In C7 type =proper(c6) then press [Enter] - your name is back to normal
22. In C8 type =exact(c7,c6) then press [Enter] - the cells do not match
23. In C9 type =exact(c7,c1) then press [Enter] - this time they do match
To learn how to convert date formats with text functions, watch the second
half of the lecture video.
The following two functions are useful for removing extra spaces from text:
24. In C10 type =substitute(c1," ","") then press [Enter] - your names merge, leaving
no space.
Sometimes you need to change text into numbers, and vice-versa. You may also need to be
able to specify a particular character by its number in the character set:
25. In D1 type =code("a") then press [Enter] - the letter a is number 97 in the character
set
26. In D2 type =char(98) then press [Enter] - guess what's the letter following a
27. In D3 type =32.5&char(176) then press [Enter] - a degree sign is added to the
figure (note that this has been stored not as a number but as text, hence it appears on
the left of the cell)
28. In D4 press [Alt =] for [AutoSum] and press [Enter] - the answer doesn't include the
value in D2 orD3
29. Replace the formula in D4 with =TEXT(CODE("a"),"#") and press [Enter]
30. In D5 type =SUM(D1:D4).
31. In cell D6 type =VALUE(D4) and press [Enter].
The TEXT function can be a very powerful function if you know how it works:
32. Move to cell B12 and type =TEXT( then press [Ctrl-A] or click on the [Insert
Function] button.
33. For the Value type now() then press [Tab] to move to Format_text
The Format_text argument is a set of characters which determines the output display for the
number generated by the TEXT function. This could be a number, time or date. The characters
used match those used in the Format Cells window. The # sign represents any number, without
specifying a format. A 0 is used where a number must be shown – so #.00 will display the
number to 2 decimal places (even when it's a whole number). In dates, d is used for days, m
for months and y for years. For times, h, m and s are used for hours, minutes and seconds.
34. For Format_text type "dddd" then press [Ctrl-Enter] - the result shows what day of
the week it is.
35. Copy cell B12 and paste in cell B13.
36. In cell B13, replace NOW() with your date of birth (in quotes, as before) and press
[Enter] to discover what day of the week you were born on.
37. Right click on the Sheet1 tab in your Book1 worksheet and choose ‘Move or Copy’.
38. In the Move or Copy dialog box, use the pulldown at the top for “To Book:” and select
your Assignment 8 file from the list.
39. Make sure the ‘Create a Copy’ box is checked and highlight ‘(move to end)’.
40. Click [OK].
Click on the File tab, save the file to your computer, then answer the functions B assessment
based on your file and/or comprehension of the lecture.