Microsoft Excel 2007-Intermediate II
Microsoft Excel 2007-Intermediate II
Example
The example below shows the Trim function used on four different text strings.
Example
The following spreadsheets show examples of use of the Excel Replace Function. The spreadsheet on the left
shows the format of the functions and the spreadsheet on the right shows the results.
Formulas Result
1
Prepared by: Elyza CH
The Excel BAHTTEXT Function
Examples
The following spreadsheet shows examples of the Excel Bahttext function. The format of the function is shown in
the spreadsheet on the left and the result is shown in the spreadsheet on the right.
Formulas Results
The
The Excel FIXED Function
Example
The spreadsheet below shows examples of use of the Excel Fixed Function. The spreadsheet on the left shows
the format of the functions and the spreadsheet on the right shows the results.
Formulas Results
Example
One of my most common uses of the Excel TEXT function is to incorporate dates into text strings.
For example, in the spreadsheet below, if I want to join together a name and a date of birth, using the simple &
operator will not give me the result I want. This is shown in the spreadsheet below, in which cell C2 uses the
simple formula :- =A2 & " " & B2 to join together the name in cell A2 and the date of birth in cell B2:
This result is returned because Excel is showing the underlying value of cell B2 which is an integer.
In order to show the name, followed by the date of birth, we need to request the value of B1 to be formatted as a
date. This can be done using the Excel TEXT function, as shown in the example below. The first spreadsheet
shows the formula and the lower spreadsheet shows the result.
Formula
Result
Examples
2
Prepared by: Elyza CH
The following spreadsheet shows the VALUE function being used for four different examples. Note that, in the
example spreadsheet, the values in cells A2 - A4 are all text values. The spreadsheet on the left shows the format
of the function and the spreadsheet on the right shows the results :
Formula Result
It is seen, from the examples above, that the Excel VALUE function can interpret different formats of numbers.
For example,
• in the example in cell B2, the function understands the text value "1.0E-07" to represent the scientific
notation for the number 0.0000001
• in the example in cell B2, the function understands the text value "50,000" to represent the number 50000
However, in the example in cell B4, the VALUE function is not able to interpret the currency $ symbol as part of a
number, so it produces the #VALUE! error message.
Example
The example below shows the function being used to 'CONCATENATE' the text strings in columns A & B of the
example spreadsheet.
A B C D
1 Name Age DOB Combined Details
2 Jane SMITH 24 29/02/84=CONCATENATE(A2,", Age ",B2)
Note that, in the example above, text blocks have been added to separate the different fields. For example, in cell
D2, the text block ", Age "has been used to separate the name and age.
Also note that in cell D3, the DOB is shown as the number 26815. This is because dates (and times) in Excel are
represented as numbers. It is only the formatting of cells that makes dates appear in the date format. The number
26815 is the numeric value associated with the date 31st May 1973 and so this is the value that the function
retrieves from cell C3.
In cell D4, the date of birth is displayed in a date format. This has been done with the use of the TEXT function,
which is used to translate the number 26815 into a text string in the date format "dd/mm/yy".
The spreadsheet below shows the results of the three CONCATENATE functions in cells D2 - D4.
A B C D
1 Name Age DOB Combined Details
2 Jane SMITH 24 29/02/84Jane SMITH, Age 24
3 Dominic DAY 35 31/05/73Dominic DAY, DOB: 26815
4 James KAY 21 02/02/87James KAY, DOB: 02/02/87
3
Prepared by: Elyza CH
Example
The following example shows the function applied to the values in cells B1 - B4 of the example spreadsheet.
A B C
Call to 'LEFT' with the num_chars
Original Text =LEFT(B1)
1 argument unspecified (default value = 1):
Call to 'LEFT' with num_chars
Original Text =LEFT(B2, 4)
2 set to 4:
Call to 'LEFT', combined with
Original Text =LEFT(B3, FIND(" ",B3)-1)
3 a call to the FIND function:
Call to 'LEFT', where the result is a digit
5 bags of coal =LEFT(B4)
4 (which is stored as text by Excel)
The third example (in cell C3) uses the FIND function, combined with the LEFT function. In this case,
the num_charsargument takes on the value returned by FIND(" ",B3)-1 (ie. the position of the character before the
first space in the supplied text).
The results of the 4 Excel LEFT functions are shown in the spreadsheet below.
A B C
Call to 'LEFT' with the num_chars
Original Text O
1 argument unspecified (default value = 1):
Call to 'LEFT' with num_chars
Original Text Orig
2 set to 4:
Call to 'LEFT', combined with
Original Text Original
3 a call to the FIND function:
Call to 'LEFT', where the result is a digit
5 bags of coal 5
4 (which is stored as text by Excel)
As previously mentioned, the value of "5" that has been returned in cell C4 is actually recognised by Excel as text.
Therefore, Excel will not recognise this as a numeric value unless it is converted to a number. One way of doing
this is by using the VALUE function.
Example
The following example shows the function applied to the values in cells B1 - B4 of the example spreadsheet.
A B C
Call to 'MID' with start_num set
Original Text =MID(B1,4,3)
1 to 4 and num_chars set to 3:
Call to 'MID' with start_num
Original Text =MID(B2,10,3)
2 set to 10 and num_chars set to 3:
Call to 'MID', combined with the
Original Text =MID(B3,FIND("T",B3),3)
3 FIND function:
Call to 'MID', where the result is a digit
I have 5 bags =MID(B4,8,1)
4 (which is stored as text by Excel)
The third example (in cell C3) uses the FIND function, combined with the MID function. In this case,
the num_charsargument takes on the value returned by FIND("T",B3) (ie. the position of the "T" in the supplied
text).
The results of the 4 Excel MID functions are shown in the spreadsheet below.
A B C
Call to 'MID' with start_num set
Original Text gin
1 to 4 and num_chars set to 3:
2 Call to 'MID' with start_num Original Text Tex
4
Prepared by: Elyza CH
As previously mentioned, the value of "5" that has been returned in cell C4 is actually recognised by Excel as text.
Therefore, Excel will not recognise this as a numeric value unless it is converted to a number. One way of doing
this is by using the VALUE function.
Examples
The following spreadsheet shows several examples of the Excel Rept function. The format of the function is
shown in the spreadsheet on the left and the result is shown in the spreadsheet on the right.
Formulas Results
Example
The spreadsheet below shows examples of use of the Excel Lower Function. The spreadsheet on the left shows
the format of the functions and the spreadsheet on the right shows the results.
Formulas Results
Example
The spreadsheet below shows examples of use of the Excel Proper Function. The spreadsheet on the left shows
the format of the functions and the spreadsheet on the right shows the results.
Formulas Results
5
Prepared by: Elyza CH
Example
The spreadsheet below shows examples of use of the Excel Upper Function. The spreadsheet on the left shows
the format of the functions and the spreadsheet on the right shows the results.
Formulas Results
6. Information Functions
Examples
The examples below show the 'LEN' of the two text strings in column B of the example spreadsheet. Note that the
text in column B is underlined, so that you can easily see where the spaces are.
A B C
Cell B1 contains just one space
Text String =LEN(B1)
1 between words:
Cell B2 has one space between
Text String =LEN(B2)
2 words and 4 spaces at the end:
The results of the LEN function, applied to cells B1 to B2 ofthe example spreadsheet, are shown below. Note that
the function includes spaces, in its calculated length, as well as other characters.
A B C
Cell B1 contains just one space
Text String 11
1 between words:
Cell B2 has one space between
Text String 15
2 words and 4 spaces at the end:
Examples
The following spreadsheet shows several examples of the Excel Exact function. The format of the function is
shown in the spreadsheet on the left and the result is shown in the spreadsheet on the right.
Formulas Results
6
Prepared by: Elyza CH
Examples
The following spreadsheet shows several examples of the Excel T function. The format of the function is shown in
the spreadsheet on the left and the result is shown in the spreadsheet on the right.
Formulas Results
Note that, in cells B2 and B3 of the above example spreadsheet, the T function returns an empty string. This is
because the supplied arguments are the number 25 and the logical value FALSE, not text values.
Examples
The following examples show the AND function applied to a number of different conditions. The format of the
functions are shown in the spreadsheet on the left and the result is shown in the spreadsheet on the right
A B C A B C
1 5 10=AND( A1>0, A1<B1 ) 1 5 10 TRUE
2 5 10=AND( A2>0, A2<B2, B2>12 ) 2 5 10 FALSE
3 5 10=AND( A3<0, A3>B3, B3>12 ) 3 5 10 FALSE
Examples
The following examples show the OR function applied to a number of different conditions. The format of the
functions are shown in the spreadsheet on the left and the result is shown in the spreadsheet on the right.
A B C A B C
1 5 10 =OR( A1>0, A1<B1 ) 1 5 10 TRUE
7
Prepared by: Elyza CH
Examples
The following spreadsheets show examples of the NOT function. The spreadsheet on the left shows the format of
the functions and the spreadsheet on the right shows the results :
2. Conditional Functions
Example 1
The following example shows the Excel IF function applied to two sets of numbers. Within the function,
the Logical_test checks whether the value in column C is equal to 0, and depending on the result, the function
returns the following:
• If the value in column B is equal to 0, the result of the function is set to #N/A. (In the example, Excel's
NA() function is used to return this error value).
• If the value in column B is non-zero, then the function returns the value in column A divided by the value
in column B.
The format of the IF function is shown in the spreadsheet on the left and the result is shown in the spreadsheet on
the right.
A B C A B C
1 5 4 =IF(B1=0, NA(), A1/B1) 1 5 4 1.25
2 5 0 =IF(B2=0, NA(), A2/B2) 2 5 0 #N/A
Example 2
The Logical_test within the Excel IF function can use any type of expression that returns
a TRUE or FALSE result. The following example shows some more examples of the function, using different
types of Logical_test. Again, the format of the function is shown in the spreadsheet on the left and the result is
shown in the spreadsheet on the right:
A B A B
1 5 =IF(A1≥0, A1, -A1) 1 5 5
2 -5 =IF(A2≥0, A2, -A2) 2 -5 5
3 0 =IF(ISERROR(1/A3), 1, A3) 3 0 1
4 test =IF(LEN(A4)<>0, 1, 0) 4 test 1
The Excel IFERROR function tests if an initial supplied value (or expression) returns an Excel Error, and if so,
returns a second supplied argument; Otherwise the function returns the initial supplied value.
8
Prepared by: Elyza CH
The IFERROR function is new to Excel 2007, so is not available in earlier versions of MS Excel
The format of the function is:
IFERROR( Value, Value_if_Error )
I personally have found the Excel Iferror function to be a useful addition in Excel 2007. Previously, in Excel 2003,
whenever I used the Vlookup function I would frequently also use the IF function with the ISERROR function to
test for an error and return an appropriate result. This is shown in the following formula:
IF( ISERROR(VLOOKUP(...)), "", VLOOKUP(...) )
the above formula checks if the VLOOKUP function returns an error, and if so, returns a blank (""). Otherwise the
value of the VLOOKUP is returned. Although this formula is long and inefficient (as it requires 2 seperate calls to
the VLOOKUP function), it helps to keep my spreadsheet cells tidy and free from messy error messages.
In Excel 2007, I can perform the above action much more efficiently and neatly, by using the IFERROR function.
The new formula is written as:
IFERROR( VLOOKUP(...), "" )
The Excel TRUE function simply returns the logical value True.
The function takes no arguments and therefore, the format is simply:
TRUE()
Throughout your spreadsheet, instead of calling the TRUE function, you can simply type the text True into your
spreadsheet, and Excel will interpret this as the logical value True.
The Excel FALSE function simply returns the logical value False.
The function takes no arguments and therefore, the format is simply:
FALSE()
Throughout your spreadsheet, instead of calling the FALSE function, you can simply type the text False into your
spreadsheet, and Excel will interpret this as the logical value False.
Examples
The following spreadsheets show examples, of the Excel ISERROR function being used to determine whether a
value or expression returns an error. The spreadsheet on the left shows the formulas used and the spreadsheet
on the right shows the results :
9
Prepared by: Elyza CH
In the examples above, the arguments to the ISERROR function calls are :
• Simple values in cells B1 - B3
• Expressions in cells B4 & B5 (note the division by zero in cell B4 will produce the #DIV/0! error)
• Cell references in cells B6 & B7
Examples
The spreadsheets below show examples of the Excel ISERR function. The spreadsheet on the left shows the
formulas used and the spreadsheet on the right shows the results :
In the examples above, The arguments to the ISERR function calls are :
• Simple values in cells B1 - B3
• Expressions in cells B4 & B5 (note the division by zero in cell B4 will produce the #DIV/0! error)
• Cell references in cells B6 - B8
Examples
The following spreadsheet shows examples, of the Excel ISNA function being used to determine whether a value
or expression returns an error :
The results of the above function calls are shown in the spreadsheet below :
10
Prepared by: Elyza CH
Examples
The following spreadsheets show examples of the Excel Error.Type function. The format of the function is shown
in the spreadsheet on the left and the results are shown in the spreadsheet on the right.
Note that the last example, in cell B4, tests the contents of cell A4, which is not an error. Therefore, the
Error.Type function returns its own error message, #N/A.
Examples
The following spreadsheets shows examples, of the Excel ISBLANK function being used to determine whether a
cell is empty or not. The format of the function is shown in the spreadsheet on the left and the results are shown
in the spreadsheet on the right :
Examples
11
Prepared by: Elyza CH
The spreadsheets below show examples of the Excel ISLOGICAL function. The spreadsheet on the left shows
the formulas used and the spreadsheet on the right shows the results :
Examples
The spreadsheets below show examples of the Excel Isref function. The spreadsheet on the left shows the format
of the function and the spreadsheet on the right shows the results :
Note that :
• The text value "A1" is not a reference. This needs to be converted using the Indirect function (see cell A5
of the above example) to make this into a reference.
• The function in cell A6 evaluates to False, as the expression A1 * B1 returns a value.
Examples
The spreadsheets below show examples of the Excel Isnumber function. The spreadsheet on the left shows the
format of the function and the spreadsheet on the right shows the results :
Examples
The spreadsheets below show examples of the Excel ISEVEN function. The spreadsheet on the left shows the
formulas used and the spreadsheet on the right shows the results :
12
Prepared by: Elyza CH
Note that the examples in cells A1 and A5 above show that the ISEVEN function returns True for a zero, or an
empty cell.
Examples
The spreadsheets below show examples of the Excel ISODD function. The spreadsheet on the left shows the
formulas used and the spreadsheet on the right shows the results :
Examples
The following spreadsheet shows several examples of the Excel N function. The format of the function is shown in
the spreadsheet on the left and the result is shown in the spreadsheet on the right.
Formulas Results
Note that, in cells B3 of the above example spreadsheet, the date 01/01/2010 is converted to the serial number
40179. However, this serial number may be different on different systems.
Examples
The following spreadsheets show examples, of the Excel Info function. The format of the function is shown in the
spreadsheet on the left and the results are shown in the spreadsheet on the right.
13
Prepared by: Elyza CH
Example
The following spreadsheet shows the function applied to 3 different data sets:
The resulting three dates are shown in the spreadsheet below (in the date format dd/mm/yyyy).
Note that the last example, shown in cell D4, also makes use of the LEFT function, to extract the day number, 21,
from the cell A4. Even though the LEFT function returns a string (rather than an integer), Excel is able to convert
this string into a number, during its calculation of the DATE.
Example
The following spreadsheet shows several different examples of the TIME function. The format of the function is
shown in the spreadsheet on the left and the results are shown in the spreadsheet on the right :
The results in column E of the spreadsheet above, are formatted with the Time format hh:mm:ss.
Also note that, in cell E4, of the example above, the seconds argument is 73. However, the TIME function is able
to convert this into 1 minute and 13 seconds.
Examples
14
Prepared by: Elyza CH
The following spreadsheet shows several examples of the Excel Datevalue function. The format of the function is
shown in the spreadsheet on the left and the result is shown in the spreadsheet on the right.
Formulas Results
Note that, in the above example spreadsheet, the text string in cell A5 contains just a day and month. In this case
the returned date will use the current year. As these examples were input into Excel in the year 2010, the
returned date has the year 2010.
Formatting
There is a good chance that your result from the Excel Datevalue function will initially be displayed as a serial
number (eg. 39814). This is because the cell containing the formula is not formatted to show dates.
To change the formatting to a date format:
• Highlight the cell(s) to be formatted
• Right click with the mouse
• Select the Format Cells ... option and ensure the Number tab is selected
• Under the Category heading, select the option Date. Select a date format from the list on the right and
click OK
Examples
The following spreadsheet shows several examples of the Excel Timevalue function. The format of the function is
shown in the spreadsheet on the left and the result is shown in the spreadsheet on the right.
Formulas Results
Formatting
There is a good chance that your result from the Excel Timevalue function will initially be displayed as a decimal
number (eg. 0.0993). This is because the cell containing the formula is not formatted to show times.
To change the formatting to a time format:
• Highlight the cell(s) to be formatted
• Right click with the mouse
• Select the Format Cells ... option and ensure the Number tab is selected
• Under the Category heading, select the option Time and click OK
Examples
The following spreadsheet shows the Excel Hour function applied to several different supplied times. The
spreadsheet on the left shows the format of the function and the spreadsheet on the right shows the results.
Formulas Results
15
Prepared by: Elyza CH
Note that, in the above examples, the time shown in cell A4 is actually a whole day plus the time 05:11:22.
Therefore, when supplied with thistime value, the Hour function ignores the full day and simply returns the hour
value 5.
Examples
The following spreadsheet shows the Excel Minute function applied to several different supplied times. The
spreadsheet on the left shows the format of the function and the spreadsheet on the right shows the results.
Formulas Results
Examples
The following spreadsheet shows the Excel Second function applied to several different supplied times. The
spreadsheet on the left shows the format of the function and the spreadsheet on the right shows the results.
Formulas Results
Example
The following two spreadsheet snapshots show examples of the EDATE function. The spreadsheet on the left
shows the function formats and the spreadsheet on the right shows the results.
Fu
nction Format Results
16
Prepared by: Elyza CH
Note how you can use negative values for the months argument, to get a date that is before the
supplied start_date. Also note how the function manages to cope with months that do not contain the same day
number as thestart_date ie. there is no 31st day of November, so the function returns the 30th. Similarly, the
function can handle the leap year day - returning 28/02/2009 as the date 12 months after 29/02/2008.
Example
The following two spreadsheet snapshots show examples of the EOMONTH function. The spreadsheet on the left
shows the function formats and the spreadsheet on the right shows the results.
Examples
The spreadsheets below show simple examples of the Excel Workday function. The format of the function is
shown in the top spreadsheet and the results are shown in the spreadsheet below.
Formulas
Results
In the example :
• In cell D2 the Holidays array has been omitted. Therefore the calculation excludes Saturdays and
Sundays but includes all other weekdays, including the holidays at Christmas and New Year.
• In cells D3 and D4 the Holidays array (in cells B2 - B4) is provided to the Workday function. Therefore the
calculation excludes Saturdays and Sundays and the listed Christmas and New Year holidays.
Examples
The spreadsheets below show simple examples of the Excel Networkdays function. The format of the function is
shown in the top spreadsheet and the results are shown in the spreadsheet below.
17
Prepared by: Elyza CH
Formulas
Results
In the example :
• The Holidays array has been omitted from the calculation in cell A8. Therefore this result excludes
Saturdays and Sundays but includes all other weekdays, including the holidays at Christmas and New
Year.
• In cells A9 and A10 the Holidays array (in cells B3 - B5) is provided to the Networkdays function.
Therefore the results in these cells exclude Saturdays and Sundays and the listed Christmas and New
Year holidays.
Example
The following example shows use of the NOW function, combined with the IF function, to highlight when an
appointment is due. The function format is shown in the first spreadsheet and the results at 2 different times are
shown in the two spreadsheets underneath.
In the above example, the current time (returned by the NOW function) is subtracted from the appointment time
and the result is compared against 1 hour. If the current time is less than 1 hour from the appointment time, the
alert is shown; otherwise no text is shown in cell B2. The contents of cell B2 have also been formatted to have red
18
Prepared by: Elyza CH
bold text, to make the alert stand out more.
Example
The following spreadsheets show 2 simple examples of calls to the function, 'TODAY', which were made on 16th
November 2008. The first example shows the function used alone, and the second example shows the function
used as a part of a formula that calculates the number of days that have passed since 31/12/2007. The
spreadsheet on the left shows the format of the formulas and the spreadsheet on the right shows the results.
Formulas
Results on 16-Nov-08
Example
The following example shows the function applied to 3 different dates. The spreadsheet on the left shows the
format of the function and the spreadsheet on the right shows the returned DAY value, for the 3 dates.
Example
The following example shows the function used to extract the MONTH from 3 different dates. The spreadsheet on
the left shows the format of the function and the spreadsheet on the right shows the result for the 3 dates.
Example
One use for the Excel Weeknum function is if you have a large number of events and you want to analyse the
peak weeks throughout the year. The spreadsheet below shows part of a spreadsheet in which the days of
specific events are stored in column A. The function has then been inserted in every cell of column B, to show the
week number of each event.
The function format is shown in the spreadsheet on the left and the results are shown in the spreadsheet on the
right.
Formulas Results
19
Prepared by: Elyza CH
The pivot table enables you to clearly see that the peak
week for the events is week number 3 (13th-19th
January), which accounts for a total of 7 events.
Example
One use for the WEEKDAY function is if you have a large number of events and you want to analyse the peak
weekdays. The spreadsheet below shows part of a spreadsheet in which the days of specific events are stored in
column A. The function has then been inserted in every cell of column B, to show the weekday of each date in
column A. The function format is shown in the spreadsheet on the left and the results are shown in the
spreadsheet on the right.
20
Prepared by: Elyza CH
Formulas Results
• Click OK
Note that the column showing the weekdays in the above pivot table has been formatted to show the
weekdaynames (see tip). The pivot table enables you to clearly see that the peak weekday for the data is
Tuesday.
Examples
The following spreadsheets show simple examples of the Excel ADDRESS function. The format of the function is
shown in the spreadsheet on the left and the results are shown in the spreadsheet on the right.
21
Prepared by: Elyza CH
Note that cell A5 in the above spreadsheet combines the ADDRESS function with the ROW function and
the COLUMN function to display the reference to the current cell.
Example 1
The following spreadsheets shows several examples of the OFFSET function being used to reference different
cell ranges. In each example, the initial supplied range is highlighted in green and the resulting range that is
returned by the function is shown in red.
=OFFSET( B1:B6, 4, 2 )
=OFFSET( D3, 1, -2 )
=OFFSET( B2, 2, 1, 1, 4 )
=OFFSET( B2, 3, 0, 3, 2 )
Note that in the above examples, the function returns a cell range. Therefore, if you attempt to display the result in
a cell, you will get an error message (eg. the first example above returns the range D5:D10 - but if you typed
"=D5:D10" into a cell you would get an error).
The following Example shows a practical use of the OFFSET function, where the results of the function are used
in a further function.
22
Prepared by: Elyza CH
Example 2
The above examples all return cell ranges, but do not show you ways in which you might make practical use of
the OFFSET function. This is addressed in the following spreadsheet, which uses the OFFSET function to return
different cell ranges, depending on the weekday shown in the cell B1 and then uses the returned range in a
further calculation :
In the above spreadsheet, the OFFSET function is used in cells B2 and B3, to reference the sales figures for the
weekday selected in cell B1. In both cells, the function uses the same arguments.
• The initial cell range is cell A5. This is the cell from which the offset is applied.
• The MATCH Function is used to identify which row (from A6 to A12) contains the weekday shown in cell
B1. This will give the result, 1 if B1="Sunday", 2 if B1="Monday", etc. This number then supplies
the rows argument for the OFFSET. (ie. the number of rows to offset from the initial cell, A5).
• The cols argument is set to 1, so the start of the returned cell range is offset 1 column from the start cell,
A5 (ie. the returned cell range always starts in column B).
• The height argument is set to 1, so the returned range is 1 cell high
• The width argument is set to 4, so the returned range is 4 cells wide
These arguments cause the OFFSET function to return the range of cells containing the sales figures for the
weekday shown in cell B2. The results from this function are then fed into the SUM Function (in cell B2) and
the AVERAGE Function (in cell B3), so that these 2 cells show the SUM and AVERAGE of the sales figures for
the selected weekday. The results for the weekday 'Tuesday' are show on the right.
Example
The following spreadsheets show several calls to the ROW function. The spreadsheet on the left shows the
format of the function and the spreadsheet on the right shows the results :
23
Prepared by: Elyza CH
Example
The following spreadsheets show several calls to the COLUMN function. The spreadsheet on the left shows the
format of the function and the spreadsheet on the right shows the results :
Examples
The following spreadsheets show simple examples of the Excel ROWS function. The format of the function is
shown in the spreadsheet on the left and the results are shown in the spreadsheet on the right.
Note that the formula in cell A3 returns 1,048,576, as this is the number of rows in Excel 2007. If this example
were run in Excel 2003, it would return 65,536.
The Excel COLUMNS Function
Examples
The following spreadsheets show simple examples of the Excel COLUMNS function. The format of the function is
shown in the spreadsheet on the left and the results are shown in the spreadsheet on the right.
Note that the formula in cell A3 returns 16,384, as this is the number of columns in Excel 2007. If this example
were run in Excel 2003, it would return 256.
Examples
The following spreadsheets show simple examples of the Excel AREAS function. The format of the function is
shown in the spreadsheet on the left and the results are shown in the spreadsheet on the right.
Example 2
24
Prepared by: Elyza CH
The following spreadsheet shows another example of the AREAS function, where the Reference is the named
range 'TestRange', which is made up of the 3 areas shown on the spreadsheet on the left. As shown in the
spreadsheet on the right, the Areas function returns the result 3.
Example
Imagine you have a table of exam results, as shown in the spreadsheet below.
In a separate spreadsheet, you just want to show the results for one individual. We can use the Excel HLOOKUP
function to look up the results for the name on the separate spreadsheet.
This is shown in the example spreadsheet below, which uses the Excel HLOOKUP to look up the exam results for
'Cara'. The spreadsheet on the left shows the format of the Hlookup function and the spreadsheet on the right
shows results. Note that, in this example, the overall results table is located in a separate worksheet, called
'Results', within the current workbook :
In the above example, the Hlookup function searches through the top row of the table_array (the range B2:G6 on
the 'Results' worksheet), to find a match for the value in cell B2 (currently set to 'Cara'). when it finds the name
'Cara', it returns the value from the requested row.
This is illustrated on the right for the function in cell B6. The function finds the name 'Cara' in the top row of
the table_array and then returns the value from the 5th row of the table_array.
25
Prepared by: Elyza CH
If we change the name in the individual spreadsheet from 'Cara' to 'Ed', the Hlookup functions would
automatically recalculate the functions to display the exam results for Ed.
Example
Imagine you are the manager of a local shop or convenience store. In the example below, the 'Supplier Costs'
spreadsheet shows a list of goods from one of your suppliers, with the wholesale purchase cost and the 'Order'
spreadsheet shows a list of supplies that you currently require.You want to enter the cost of each item into
column C of your 'Order' spreadsheet, so that you can work out how much the order will cost.
Supplier Costs:
You can use the Excel A B C
VLOOKUP function to 'look 1 Item Code Item Description Cost ($)
up' the order number on the 2 101Tinned Tomatoes 450g $0.30
'Supplier Costs' spreadsheet 3 102Tinned Tuna 190g $0.65
and insert each item price
4 103Cornflakes 500g $1.55
into column 'D' of your
5 104Shortcake Biscuits 200g $0.42
'Order' spreadsheet. The
following spreadsheet shows 6 105Toothpaste 100ml $1.23
the format of the Excel 7 106Tinned Baked Beans 450g $0.32
VLOOKUP function in this 8 107White Sliced Loaf 800g $0.55
case: 9 108Frozen Beef Lasagne $1.65
A B C D E F G
Order:
Item Description Quantity Cost ($)
Item Code
1 A OrderedB C D
2 102Tinned Tuna Quantity
20=VLOOKUP(A2,'Supplier Costs'!A:C,3,0)
Item Code Item Description Cost ($)
3 1
106Tinned Baked Beans 50 Ordered
$0.32
4 2 Sliced Loaf
107White 102Tinned Tuna20 $0.55 20
5 3
103Cornflakes 106Tinned Baked 10 Beans
$1.55 50
4 107White Sliced Loaf 20
In this example, the 5 103Cornflakes 10
arguments for the Excel
VLOOKUP function are :
A2 The lookup_value is set to A2, indicating that we want to 'look up' the value of the cell A2
(ie. the item code 102) in the 'Supplier Costs' spreadsheet
'Supplier Costs'!A:C The table_array argument is set to 'Supplier Costs'!A:C indicating that the array we wish
to search is contained within columns A-C of the worksheet named 'Supplier Costs'
Note:
- In this example, the 'Supplier Costs' worksheet is in the same workbook as the current
worksheet (the 'Costs' worksheet). If this sheet was located in a separate workbook,
the table_array argument would need to include the name of the other workbook.
However, you don't need to worry about remembering the formats for referencing other
workbooks, as you can easily insert the required range by highlighting it, using the mouse.
3 The col_index_number is set to 3, indicating that the value we want the function to return
lies in the 3rd column of the table_array (ie. we want to return the Item Cost, which is in the
3rd column of the supplied range'Supplier Costs'!A:C
0 In the above example, the range_lookup argument is set to 0, indicating that we only want
the Excel VLOOKUP function to return a value if it finds an exact match to the item code.
- Obviously, we wouldn't want the function to return the cost of a different item, if the item
we are looking for is not found!
26
Prepared by: Elyza CH
Imagine you are compiling a list of examination results for a class of students. You have a list that tells you what
grade is assigned to different percentages scores and you have a separate list of percentages that each student
scored in the exam. You need to allocate a grade to each student's examination mark. This is shown in the 2
spreadsheets below:
Grades Spreadsheet Exam Results Spreadsheet
A B C A B C
1 Lower Upper Grade 1 Name Percentage Grade
2 0% 34% F 2 ASH, Kelly 57%
3 35% 44% E 3 AVIS, Ben 86%
4 45% 54% D 4 BUX, David 46%
5 55% 64% C 5 CRAY, John 29%
6 65% 75% B
7 75% 100% A
The Excel LOOKUP function can be used to 'look up' the grade that is associated with the percentage that was
scored by each student. The formula for this is shown in the spreadsheet below.
A B C D E F G
1 Name Percentage Grade
2 ASH, Kelly 57%=LOOKUP( B2, Grades!A$2:A$7, Grades!C$2:C$7 )
3 AVIS, Ben 86%=LOOKUP( B3, Grades!A$2:A$7, Grades!C$2:C$7 )
4 BUX, David 46%=LOOKUP( B4, Grades!A$2:A$7, Grades!C$2:C$7 )
5 CRAY, John 29%=LOOKUP( B5, Grades!A$2:A$7, Grades!C$2:C$7 )
The above formula will only work if the lookup_vector (i.e. the 'Lower' Note:
column) is ordered numerically. The $ symbol used in the terms
The results of the above calls to the LOOKUP function are shown in A$2:A$7 and C$2:C$7 prevents the
the spreadsheet below. As expected, the function has successfully references to vectors A2:A7 and
returned the exam grade linked to each student. C2:C7 from automatically adjusting
(eg. to A3:A8, A4:A9, etc), as the
formula is copied down to other cells.
A B C
1 Name Percentage Grade
2 ASH, Kelly 57% D
3 AVIS, Ben 86% A
4 BUX, David 46% E
5 CRAY, John 29% F
Note that the VECTOR form of the Excel LOOKUP function can be used with any two sets of data that have one-
on-one matching values. For example, two rows of data, or even a column and a row would work, as long as
the lookup_vector was ordered (alphabetically or numerically), and the two data sets were the same length.
27
Prepared by: Elyza CH
Imagine you are in charge of a number of savings accounts, which earn varying rates of interest, depending upon
the account balance. The interest rates are:
A B C
1 Account Balance Interest Rate
2 12-34-56 10000001 $75,000
3 12-34-56 20000002 $25,000
4 12-34-56 30000003 $275
5 12-34-56 40000004 $35
6 12-34-56 50000005 $1,005
Imagine you also have a spreadsheet (see right) which contains a list of bank accounts and the balance for each
account. You want to look up the interest rate that will be applied to each of these accounts.
The spreadsheet below shows the array form of the Excel LOOKUP function, used 'look up' the interest rate from
the 'Rates' spreadsheet and insert this into column C of the 'Accounts' spreadsheet.
A B C D E
1 Account Balance Interest Rate
2 12-34-56 10000001 $75,000=LOOKUP( B2, Rates!B$1:F$3 )
3 12-34-56 20000002 $25,000=LOOKUP( B3, Rates!B$1:F$3 )
4 12-34-56 30000003 $275=LOOKUP( B4, Rates!B$1:F$3 )
5 12-34-56 40000004 $35=LOOKUP( B5, Rates!B$1:F$3 )
6 12-34-56 50000005 $1,005=LOOKUP( B6 , Rates!B$1:F$3 )
The results of the Excel LOOKUP function are shown in the spreadsheet below. As required, the function has
inserted the interest rate relating to the balances in each of the listed bank accounts.
A B C
1 Account Balance Interest Rate
2 12-34-56 10000001 $75,000 7%
3 12-34-56 20000002 $25,000 6%
4 12-34-56 30000003 $275 4%
5 12-34-56 40000004 $35 3%
6 12-34-56 50000005 $1,005 5%
In this example, the Excel LOOKUP function recognised that it was searching for the lookup_value in the
first row of the supplied array, and returning a value from the last row. However if the array is transposed so that
the data runs down 3columns, the function will recognise this, and will still return the correct values.
Examples
The examples below all refer to the following Pivot Table, which is located in columns A - G of the current Excel
Worksheet.
A B C D E F G
28
Prepared by: Elyza CH
1
2 Sum of Invoice Amount TotalItem Type
3 Date Salesperson Digital TV DVD PlayerIPod Computer Grand Total
4 Jan John $68,600 $13,800 $6,840 $69,600 $158,840
5 Kevin $64,400 $7,800 $12,780 $36,800 $121,780
6 Pete $46,200 $2,400 $2,700 $25,600 $76,900
7 Jan Total $179,200 $24,000 $22,320 $132,000 $357,520
8 Feb John $68,600 $8,400 $9,720 $52,800 $139,520
9 Kevin $61,600 $4,500 $7,920 $43,200 $117,220
10 Pete $29,400 $3,900 $6,300 $33,600 $73,200
11 Feb Total $159,600 $16,800 $23,940 $129,600 $329,940
12 Mar John $71,400 $9,300 $7,560 $80,000 $168,260
13 Kevin $70,000 $10,200 $13,680 $58,400 $152,280
14 Pete $43,400 $5,400 $3,240 $40,800 $92,840
15 Mar Total $184,800 $24,900 $24,480 $179,200 $413,380
16 Grand Total $523,600 $65,700 $70,740 $440,800 $1,100,840
17
=GETPIVOTDATA( "Invoice Amount", $A$2, "Date", "Feb", "Item Details", "IPod", "Salesperson", "Kevin" )
- Returns the value $7,920, which is the value of the Invoice Amount Total for the Date field, "Feb", the Item
Details field, "IPod", and the Salesperson field "Kevin".
Examples
Imagine you are working on the spreadsheet below and you want to set the cells in Column B, to have the
following values, depending on the content of the corresponding cell in Column A.
1 - red; 2 - blue; 3 - green; 4 - brown; 5 - purple; 6 - orange; 7 - yellow; 8 - grey
The Excel CHOOSE function can be used to assign the correct value to the cells of Column B, as shown below:
A B C D E F G H I
1 4=CHOOSE(A1,"red","blue", "green", "brown", "purple", "orange", "yellow", "grey")
2 5=CHOOSE(A2,"red","blue", "green", "brown", "purple", "orange", "yellow", "grey")
3 6=CHOOSE(A3,"red","blue", "green", "brown", "purple", "orange", "yellow", "grey")
4 7=CHOOSE(A4,"red","blue", "green", "brown", "purple", "orange", "yellow", "grey")
5 2=CHOOSE(A5,"red","blue", "green", "brown", "purple", "orange", "yellow", "grey")
6 3=CHOOSE(A6,"red","blue", "green", "brown", "purple", "orange", "yellow", "grey")
7 1=CHOOSE(A7,"red","blue", "green", "brown", "purple", "orange", "yellow", "grey")
8 10=CHOOSE(A8,"red","blue", "green", "brown", "purple", "orange", "yellow", "grey")
9 9=CHOOSE(A9,"red","blue", "green", "brown", "purple", "orange", "yellow", "grey")
10 8=CHOOSE(A10,"red","blue", "green", "brown", "purple", "orange", "yellow", "grey")
The results of the above Excel CHOOSE functions are shown below:
A B
29
Prepared by: Elyza CH
1 4brown
2 5purple
3 6orange
4 7yellow
5 2blue
6 3green
7 1red
8 8grey
Example 1
A B
1 1=MATCH( 7, A:A, 1 )
2 3=MATCH( 6, A:A, 1 )
3 5=MATCH( 7, A:A, 0 )
4 7=MATCH( 6, A:A, 0 )
5 9=MATCH( 7, A:A, -1 )
6 11=MATCH( 6, A:A, -1 )
The spreadsheet on the left shows the Excel MATCH function used against a Lookup_Array that is in ascending
order. The spreadsheet includes examples in which the Match_Type argument is set to 1, 0 or -1 and shows the
results obtained for two different Lookup_Values, one of which is contained in the Lookup_Array and one of which
is not contained in the Lookup_Array.
The results of the function calls are shown in the spreadsheet below.
A B C
1 1 4Returns posn. 4, (relating to the value '7')
Returns posn. 3 (relating to the value '5' ie. the nearest
2 3 3value below the Lookup_Value '6')
3 5 4Returns posn. 4, (relating to the value '7')
4 7#N/A Returns error, as the Lookup_Value '6' cannot be found
5 9#N/A Returns error, as column A is not in decending order
6 11#N/A Returns error, as column A is not in decending order
Example 2
A B
1 11=MATCH( 7, A:A, 1 )
2 9=MATCH( 6, A:A, 1 )
3 7=MATCH( 7, A:A, 0 )
4 5=MATCH( 6, A:A, 0 )
5 3=MATCH( 7, A:A, -1 )
6 1=MATCH( 6, A:A, -1 )
The spreadsheet on the left shows the Excel MATCH function used against a Lookup_Array that is in decending
order. As in the previous example, the spreadsheet includes examples in which theMatch_Type argument is set
to 1, 0 or -1 and shows the results obtained for two differentLookup_Values, one of which is contained in
the Lookup_Array and one of which is not contained in the Lookup_Array.
The results of the function calls are shown in the spreadsheet below. The first two examples produce an incorrect
result. This is because the Lookup_Array is not in decending order.
A B C
1 11 6Returns the incorrect position 6
2 9 6Returns the incorrect position 6
30
Prepared by: Elyza CH
3 7 3Returns posn. 3, (relating to the value '7')
4 5#N/A Returns error, as the Lookup_Value '6' cannot be found
5 33 Returns posn. 3, (relating to the value '7')
Returns posn. 3 (relating to the value '7' ie. the nearest
6 13 value above the Lookup_Value '6')
Examples
The following spreadsheets show simple examples of the Excel Abs function. The format of the function is shown
in the spreadsheet on the left and the results are shown in the spreadsheet on the right.
Formulas Results
Examples
The following spreadsheets show simple examples of the Excel Sign function. The format of the function is shown
in the spreadsheet on the left and the results are shown in the spreadsheet on the right.
Formulas Results
Examples
The following example shows the function used to SUM the same set of numerical values in 4 different ways.
A B C D E F G H
1 Score1 Score2 Score3 Score4 Score5 Total Score
2 8 7 9 6 10 =SUM(8, 7, 9, 6, 10)
3 8 7 9 6 10 =SUM(A3, B3, C3, D3, E3)
4 8 7 9 6 10 =SUM(A4:E4)
5 8 7 9 6 10 =SUM(8, B5, C5:E5)
31
Prepared by: Elyza CH
The result of each of the above SUM functions is 40, as they all calculate the SUM of the same 5 numbers:
A B C D E F
1 Score1 Score2 Score3 Score4 Score5 Total Score
2 8 7 9 6 10 40
3 8 7 9 6 10 40
4 8 7 9 6 10 40
5 8 7 9 6 10 40
Examples
The following spreadsheet shows four different ways to input the same five numbers into the Excel Product
function. The example shows how the Number arguments can be input as:
- individual numbers
- number arrays
- individual cells
- cell ranges
... or a combination of all of these.
The spreadsheet on the left shows the format of the functions, and the spreadsheet on the right shows the
results.
Formulas Results
Examples
The following spreadsheets show simple examples of the Excel Mod function. The format of the function is shown
in the spreadsheet on the left and the results are shown in the spreadsheet on the right.
Formulas Results
Example 1
In this example, the Subtotal function is used to calculate the sum and the average monthly sales per team. All of
the cells in the range of sales figures are visible, so all values are included in the subtotal calculations :
Formulas Result
32
Prepared by: Elyza CH
Note that, in the example above, as all cells are visible, we could have set the Function_num argument to either 9
or 109 for the sum - both values would give the same result. Similarly, using either 1 or 101 for the average would
give the same results.
Example 2
In this example, the teams have been filtered, using the Excel Autofilter, to show Team 1 only. In this case, the
Subtotal function's calculations will be for the visible cells only (ie. for Team 1 only) :
Formulas Result
Note that, in the example above, because the rows for Teams 2 & 3 have been filtered out, using the Excel
Autofilter, we could have used aFunction_num argument of either 9 or 109 to give the same sum, (ie. the sum for
the Team 1 sales only). Similarly, we could have used either 1 or 101 to give the same the average calculation.
Example 3
In this example, rows 3, 4, 6, 7, 9, and 10 of the spreadsheet have been hidden using row formatting. (ie. by
highlighting these rows, right clicking with the mouse and selecting Hide).
In the spreadsheet below, the Subtotal function is used to calculate the sum and the average monthly sales
across ALL teams. Because we are using the values of 9 and 1 for the Function_num arguments, the hidden
cells are included in the calculations :
Formulas Result
Note that, in the example above, we could exclude the hidden values from the calculations by using
the Function_num values of 109 and 101 for the sum and average functions respectively.
3. Conditional Sums
Example 1
The following example shows the Excel SUMIF function using critia based on text strings, numerical values or
logical values.
33
Prepared by: Elyza CH
The spreadsheet on the left shows the format of the functions and the spreadsheet on the right shows the results
from the function calls.
Equations Results
A B C A B
1 Monday 500 1 Monday 500
2 Tuesday 50 2 Tuesday 50
3 Thursday 100 3 Thursday 100
4 Friday 100 4 Friday 100
5 Thursday 200 5 Thursday 200
6 5 300 6 5 300
7 2 200 7 2 200
8 3 100 8 3 100
9 4 50 9 4 50
10 5 100 10 5 100
11 1 100 11 1 100
12 0 200 12 0 200
13 1 250 13 1 250
14 1 50 14 1 50
15 15
16 =SUMIF( A$1:A$14, "Thursday", B$1:B$14 ) 16 300
17 =SUMIF( A$1:A$14, 5, B$1:B$14 ) 17 400
18 =SUMIF( A$1:A$14, ">2", B$1:B$14 ) 18 550
19 =SUMIF( A$1:A$14, TRUE, B$1:B$14 ) 19 400
20 =SUMIF( A$1:A$14, "<>TRUE", B$1:B$14 ) 20 1900
In the above example, the Excel SUMIF function in cell A16 checks the contents of cells A1 - A14. For those cells
whose contents are equal to the text string "Thursday", the corresponding values from the cells B1 - B14 are
summed. Since the contents of cells A3 and A5 both equal "Thursday", the function sums the values from the
corresponding cells B3 and B5, which are 100 and 200 respectively.
The function calls in cells A17 - A20 are evaluated in a similar way, using the criteria, 'equal to 5', 'greater than 2',
'equal to TRUE' and 'not equal to TRUE', respectively.
Example 2
The following example shows the Excel SUMIF function used to total sales figures for the person named in the
cell F1. This is done by setting the supplied Criteria to be a reference to cell F1. This causes the function to
compare the contents of cell F1 with the supplied Range (column A of the spreadsheet in the example).
In the spreadsheet below, the name "John" is typed into cell F1 and so the SUMIF function in cell E2 sums all the
sales figures that relate to 'John'. This gives the total figure of $19,000.
If the name in cell F1 is changed to "Peter", "Mary" or "Joanne", the function in cell E2 will total the sales figures
for these names accordingly.
A B C D E F
1 Name Month Sales Total Sales figures for : John
2 John May $6,000
=SUMIF( A:A, F1, C:C )
3 Peter May $4,000
34
Prepared by: Elyza CH
4 Mary May $7,000
5 Joanne May $2,000
6 John June $3,000
7 Peter June $1,000
8 Mary June $1,500
9 Joanne June $5,000
10 John July $7,000
11 Peter July $5,000
12 Mary July $6,000
13 Joanne July $6,000
14 John August $3,000
15 Peter August $4,000
16 Mary August $5,000
17 Joanne August $4,000
To make your spreadsheet more user-friendly, it would be useful to use a validation list to control the contents of
cell F1 in the above example. This would enable users of the spreadsheet to select the cell value from a drop-
down list of names and would also prevent users from inserting unexpected data into this cell.
35