F1 - Get The Most Out of Excel Formulas and Functions
F1 - Get The Most Out of Excel Formulas and Functions
F1 - Get The Most Out of Excel Formulas and Functions
ISBN: 9780974636856
Trademarks:
All brand names and product names used in this book are trade names,
service marks, trademarks, or registered trade marks of their respective
owners. Limelight Media Inc. is not associated with any product or vendor
mentioned in this book.
• Financial Statements.xls
• Mr Excel On Excel
Thanks to
Yael Schneebaum
Chris Tobin
Sara Amihud
Iki Sapoznik
Ido Ben-Horin
Use the Table of Contents at the front of the book and the Index at the
back to find the topic you are looking for.
• Title
• Problem
• Solution
• Screenshot
• Explanation
In Excel workbooks
On the Internet
• All the formula solutions presented in the book have been entered
into the www.exceltip.com database. To discuss a specific
formula, visit www.exceltip.com/fx- & the page number in the
book. For example, if you want to discuss a formula from page
100, type the following URL into your browser:
www.exceltip.com/fx-100.
Contents at a Glance
Index............................................................................................ 455
Table of Contents
Finding Every Third Number and Returning the Largest of Them ..........................190
Retrieving the Nth Value in a Row / Column ........................................................192
Retrieving Every Nth Value in a Range .................................................................193
Retrieve the Distance between Any Two Cities from Distance Table ....................194
Retrieving Matching Values from Not Adjacent List.............................................195
Retrieving Data Using Two Criteria .........................................................................196
Retrieving an Item from a List that Meets Multiple Criteria (1)...............................196
Retrieving an Item from a List that Meets Multiple Criteria (2)...............................198
Retrieving Sale Price Based on Item and Color Criteria.........................................199
Retrieving a Price from a List that Matches both Category and Item Criteria .........200
Retrieving an Entire Row of Data.............................................................................201
Retrieving the Entire Row of a Matched Value......................................................201
Returning the Entire Contents of the Row Containing the Highest Math Grade .....203
Retrieving Data from Two Different Lists.................................................................204
Retrieving a Price Value by Looking at Two Difference Data Tables.....................204
Complex Retrieval Problems ....................................................................................206
Retrieving the Column Header of the Next Non-Blank Cell in a Row ...................206
Finding the First Value in a Row and Retrieving the Header for That Column.......207
Retrieving the Column Header that Corresponds with a Matched Value...............208
Retrieving the Column Header of the Largest Value in a Row...............................210
Retrieving a Value from a Reference Grid, Using Indexes Listed in
another Range................................................................................................211
Checking for the Presence of Specified Values within a Range. ........................... 223
Handling Errors ....................................................................................................... 224
Ignoring Blank Cells when Performing Calculations............................................. 224
Avoiding the #VALUE! Error when Adding Cells that May Contain Blanks........... 225
Avoiding #DIV/0! Errors when Dividing by Zero ................................................. 226
Ignoring #DIV/0! Errors when Performing Calculations........................................ 227
Eliminating Errors Resulting from If Functions with Multiple Conditions .............. 229
Avoiding Errors when Using the And Function to Combine Multiple
Conditions in Array Formulas........................................................................ 230
Avoiding Errors when Counting Date Values that Meet Specified Criteria ............ 231
Avoiding Errors when Subtracting Times.............................................................. 233
Handling Errors with the VLOOKUP Function ........................................................ 234
Preventing a VLOOKUP Function from Returning an Error when an
Exact Match is Not Found ............................................................................. 234
Avoiding the Occurrence of Unexpected VLOOKUP #N/A Errors ....................... 235
Using a VLOOKUP Formula to Check If a Value Exists........................................ 237
Checking If Matching Numbers Exist in Different Ranges..................................... 238
Counting the Number of Strings which Contain Numbers Meeting Criteria ..........256
Counting Date Values by Specified Date Criteria..................................................257
Counting the Number of Dates with Matching Month Criteria..............................258
Counting Time Values In Terms of Hourly Increments..........................................260
Counting the Number of Values Meeting Criteria, but Only for Every 3rd |
Cell in a Range ..............................................................................................261
Counting Rows of Even Numbers in Two Parallel Ranges.....................................263
Counting the Number of Values from Multiple Worksheets that Match Criteria ....264
Counting Using Two Criteria ...................................................................................265
Counting Rows that Match Specific Criteria for Each Column...............................265
Counting the Number of Values between Two Specified Values in a List..............266
Counting the Number of Values between Upper and Lower Limits.......................268
Counting the Number of Unique Items Sold by Each Salesperson.........................269
Counting the Number of Players According to Their Score in a
Particular Quarter ..........................................................................................271
Counting the Number of Students who Answered "A" to the Second Question .....272
Counting the Number of Excel Files in a List According to File Type and
Date Criteria ..................................................................................................273
Using Date & Time Criteria to Count Entries in a Combined Date & Time List......275
Counting the Number of Items Sold Every Half Hour............................................276
Complex Counting Problems....................................................................................277
Counting the Number of Times Any of the Numbers in First List Appears
within Second List..........................................................................................277
Creating Progressively Incremented Counting Criteria ..........................................278
Counting the Values that Match Criteria in a Filtered List .....................................280
Creating a Summary Table of a Student Questionnaire .........................................281
Counting the Number of YES Responses in a Student Questionnaire ....................283
Counting Unique "X" and "O" Occurrences in a Matrix ........................................285
Creating a Counting Grid .....................................................................................286
Index............................................................................................ 455
Chapter 1
Nesting Formulas
A formula can be copied and pasted into the appropriate place within
another formula in the Formula Bar by using the <Ctrl+C> and <Ctrl+V>
keyboard shortcuts.
) Absolute Reference
Select cell B1 from the previous example. In the Formula Bar, select
A1, and then press <F4>. The result is =$A$1.
Copy the contents of cell B1 to cell B10. Notice that the formula does
not change — the formula reference remains constant as =$A$1.
Regular display:
Displaying Formulas:
1. Press <F5>.
OR
From the Edit menu, select Go To.
2. In the Go To dialog box, click Special.
3. Select Formulas, and then click OK.
Pasting Values
¾ To paste the calculated value of a single formula into a cell
(thus overwriting the formula):
Press <F2> to edit and then <F9> to calculate.
Example:
=CurrentAssets / CurrentLiabilities+ N("The formula returns Current
Ratio")
Array Formulas
Understanding Arrays
For those who do not have a background in programming or
mathematics, the expression Array may not be familiar.
So what exactly is an Array?
For our purposes, an Array is simply a set of values which can be stored
in a formula, a range of cells, or the computer’s memory.
The size of an Array can range from two to thousands of values.
Example:
To add the total sales amount of 3 items when the quantities sold are
10, 20, and 30 and the sale prices are $3, $4, and $5 respectively, the
SUMPRODUCT formula stores each multiplication product in an
Array (Array size is 3) and then adds the three values from the Array.
The SUMPRODUCT formula: =SUMPRODUCT(A1:A3,B1:B3),
Result - total sales=$260.
) Let Excel create an Array formula:
As explained in the previous section, many formulas create Arrays
when they need to store values during calculations. However, an
Excel user may create a formula that deliberately enforces the
program to open an Array/Arrays to store values.
Example:
Use the SUM function to return total sales (see previous example).
The formula will now look like this: {=SUM(A1:A3*B1:B3)}, Result-
total sales=$260.
To apply an Array formula:
Enter the formula, select the cell, press <F2>, and then simultaneously
press <Ctrl+Shift+Enter>.
Notes:
) There is no limit on the number of Names you can define.
) Be sure to define unique Names for a specific workbook. Defining
Names that resemble Names in other sheets will only complicate
your work.
Auditing Formulas
Moving Between Precedent and Dependent
Cells
¾ To move to a precedent cell(s):
Select a cell containing a formula and press <Ctrl+[>.
The <Ctrl+[> shortcut is one of the most important keyboard
shortcuts, and is highly recommended.
It can trace a precedent cell(s) in the active sheet, in another sheet in the
workbook, in a sheet in another open workbook, and it can even open a
closed workbook and select the precedent cell(s) after opening.
The Evaluate Formula dialog box allows moving between the arguments
in a formula and checking the calculation result step-by-step.
Click Step In to move between arguments.
¾ To trace an error:
1. Select cell B1 (a cell containing an error), and click Error Checking
(the first icon on the left of the Auditing Formulas toolbar).
OR
Use the Smart Tag to open the Error Checking dialog box.
2. Click Options.
Protecting Formulas
Protecting Cells Containing Formulas in a
Protected Sheet
¾ To protect cells containing Formulas, two conditions must be
met:
The cell must be locked:
Select a cell in the sheet and press <Ctrl+1>.
In the Format Cells dialog box, select the Protection tab.
Select the Locked option.
The sheet must be protected:
From the Tools menu, select Protection and then Protect Sheet.
Click OK.
) Step 1: Cancel the locked format of all the cells in the sheet:
1. Select all cells in the sheet by pressing <Ctrl+A>.
2. Press <Ctrl+1>.
3. Select the Protection tab, and deselect the Locked option.
4. Click OK.
Chapter 2
Text
This chapter provides a wide range of information on the many issues and
problems involved with the use of Text formulas. It includes the following
sections:
) Entering Text, page 27: This section covers techniques on restricting
the entry of text into a cell, restricting the number of characters that
may be entered, and preventing the entry of duplicate text.
) Combining Text, Date, & Numbers, page 30: This section deals with
formulas that combine text from different cells into one single text
value, that combine text with date values (while formatting the date)
or leading zeros, that combine every Nth cell into one single cell, and
that create new coded text.
) Text Formatting - Troubleshooting, page 36: This section contains
formulas dealing with redundant characters, hidden apostrophes, and
blank cells. Also covered are formulas erroneously appearing as text
and ways to avoid having numeric values appear as text.
) Subdividing Text, page 45: The formulas in this section deal with
mixed string & number techniques, splitting first and last names,
splitting a full address, and extracting a given number of words from a
string.
) Replacing Characters, page 50: This section covers formulas that
replace substrings with numbers while creating new strings such as a
new IP address.
Entering Text
Restricting Cell Entries to Text Only
¾ Problem:
We want to ensure that only text may be entered into the cells of column A.
¾ Solution:
Use Data Validation:
1. Select Column A.
2. Data → Data Validation → Settings → Custom
3. Enter the following formula in the Formula box:
=ISTEXT(A1)
4. Click OK.
Thus, if an entry is not text, an error message will pop up, forcing the user
to try again.
Explanation:
The ISTEXT function returns TRUE if the value in cell A1 is text and FALSE
otherwise.
The use of Data Validation prevents the user from entering values for
which the ISTEXT function returns FALSE.
¾ Solution:
Use Data Validation:
1. Select Column A.
2. Data → Data Validation → Settings → Custom
3. Enter the following formula in the Formula box:
=LEN(A2)<6
4. Click OK.
If an entry is longer than 5 characters, an error message will pop up,
forcing the user to try again.
Explanation:
The LEN function returns the number of characters stored in cell A2.
The use of Data Validation prevents the user from entering values for
which the LEN function returns a number larger than 5.
¾ Solution:
Use Data Validation as follows:
1. Select the range to validate (cells A2:A10)
2. Data → Data Validation → Settings
3. From the Allow dropdown list, select Custom.
4. Enter the following COUNTIF formula in the Formula box:
=COUNTIF($A$2:$A$10,A2)=1
5. Select the Error Alert tab.
6. In the Title box, enter "Duplicate Entry".
7. In the Error Message box, enter "The value you entered already
appears in the list above."
8. Click OK.
After following this procedure, any duplicate entry will cause the error
message to pop up, forcing the user to enter a different value.
Explanation:
The COUNTIF function returns the number of values in List1 (cells
A2:A10) that are equal to the one currently being entered.
Data Validation prevents the acceptance of a value for which the result of
the COUNTIF function is greater than 1 (i.e. that value already exists in
List1).
¾ Solution:
Use the TEXT function as shown in the following formula:
=A2&" "&TEXT(B2,"$#,##0")&" "&C2
To display the dollar amount in thousands, modify the second argument
in the TEXT function as follows:
=A2&" "&TEXT(B2,"$ #, K")&" "&C2
Explanation:
The TEXT function formats the number stored in cell B2 as a dollar
amount ("$#,##0") and converts it to text.
That text is then joined with the contents of cells A2 and C2 to create a
single string.
¾ Solution:
Use the TEXT function as shown in the following formula:
=A2&" "&TEXT(B2,"mm/dd/yyyy")
Explanation:
The TEXT function formats the date in cell B2 as "mm/dd/yyyy" and
converts it to text.
That text is then joined with the contents of cell A2 to create a single
string.
¾ Solution:
Use the TEXT function as shown in the following formula:
=TEXT(A2,"00")&TEXT(A3,"00")&TEXT(A4,"00")&TEXT(A5,"00")
Explanation:
The TEXT function formats each of the numbers in List1 as "00" and
converts them to text.
The values returned by each of the TEXT functions are then joined into a
single string.
¾ Solution:
Use the IF, MOD, and ROW functions as shown in the following formula:
=IF(MOD(ROW()-ROW($A$2),4)=0, A2&" "&A3&" "&A4&" "&A5," ")
Enter the formula in cell B2 and then copy it down the column until all
the addresses in column A are recombined.
Explanation:
The ROW functions are used to calculate the row number of each cell
within the address list.
The MOD function divides that row number by 4 and returns the remainder.
If the remainder is 0, the value in column A is the first line of one of the
addresses and the IF function returns a string consisting of the text stored
in that cell and the three cells below it.
If the remainder is not 0, the formula returns a blank cell.
¾ Solution:
Use the VLOOKUP and MID functions as shown in the following
formula:
=VLOOKUP(MID(D2,1,1),$A$2:$B$7,2,FALSE)&"
"&VLOOKUP(MID(D2,2,1),$A$2:$B$7,2,FALSE)&"
"&VLOOKUP(MID(D2,3,1),$A$2:$B$7,2,FALSE)
Explanation:
The MID function used in the first VLOOKUP function extracts the first
character in cell D2.
The VLOOKUP function looks for that character in the first column of
range A2:B7, and returns the corresponding value from the second
column. Thus, the code matching the first character in cell D2 is returned.
Similarly, the second and third VLOOKUP functions return the codes
matching the second and third characters in cell D2.
The results of all three VLOOKUP functions are joined into a single string
with spaces separating them.
¾ Solution:
Use the CONCATENATE, TEXT, and IF functions as shown in the
following formula:
= CONCATENATE("Reduced price is",
TEXT(IF(A2>80,80%*A2,90%*A2),"$00.00"))
Explanation:
The IF function determines whether or not the full price in cell A2 is
greater than $80.
If so, it returns 80% of that price. Otherwise, it returns 90 %.
The TEXT function formats the number returned by the IF function as
currency ("$00.00") and converts it to text.
Finally, the CONCATENATE function joins the text "Reduced price is"
with the result of the TEXT function.
Thus, a string is returned displaying the reduced price that matches the
full price in cell A2.
¾ Solution:
Column B was probably formatted as text prior to the formulas being
entered.
In order for the formulas to return their correct results do the following:
1. Select all the formulas.
¾ Solution:
The numbers "5" and "2", returned by the IF function in column B, are
actually text values because they are entered within double quotes.
Hence, column B contains text values, not numbers.
As the SUM function operates on numeric values only, there are no
numbers in column B to add up, and therefore, it returns 0.
¾ Solution:
Use two quote marks (""), as
shown in the adjusted formula
below, to indicate that a blank
should be returned:
=IF(ISBLANK(A2),"",A2*3)
Explanation:
The ISBLANK function determines whether or not the value in cell A2 is
blank and returns TRUE/FALSE accordingly.
If TRUE is returned, the IF function returns a blank (""). Otherwise, it
returns the value stored in A2 multiplied by 3.
¾ Solution:
Use either of the following formulas in column B:
=IF(ISBLANK(A2),"",A2)
=IF(A2="","",A2)
Either formula will return the corresponding value from column A only if
the cell is not blank.
Use the COUNTBLANK function, as shown in the following formula, to
count the number of blank cells in List1:
=COUNTBLANK(A2:A7)
Explanation:
) ISBLANK Formula:
The ISBLANK function determines whether or not the value in cell A2
is blank and returns TRUE/FALSE accordingly.
If TRUE is returned, the IF function returns a blank (""). Otherwise, it
returns the value stored in cell A2.
) COUNTBLANK Formula:
The COUNTBLANK function counts the number of blank cells within
the range A2:A7.
¾ Solution:
Use the ISBLANK function as shown in the following formula:
=IF(ISBLANK(A2)=FALSE,A2,"")
To return text values only, use the ISTEXT function as shown in the
following formula:
=IF(ISTEXT(A2),A2,"")
To return numeric values only, use the ISNUMBER function as shown in
the following formula:
=IF(ISNUMBER(A2),A2,"")
Explanation:
) ISBLANK Formula:
The ISBLANK function determines whether or not the value in cell A2
is blank and returns TRUE/FALSE accordingly.
If the result of the ISBLANK function is FALSE, the IF function returns
the value stored in cell A2. Otherwise, it returns a blank.
Thus, the corresponding value in cell A2 is returned only if it’s not
blank.
) ISTEXT Formula:
The ISTEXT function determines whether or not the value in cell A2 is
text and returns TRUE/FALSE accordingly.
If TRUE is returned, the IF function returns the value stored in cell A2.
Otherwise, it returns a blank.
Thus, the corresponding value in cell A2 is returned only if it’s a text
value.
) ISNUMBER Formula:
The ISNUMBER function determines whether or not the value in cell
A2 is numeric and returns TRUE/FALSE accordingly.
If TRUE is returned, the IF function returns the value stored in cell A2.
Otherwise, it returns a blank.
Thus, the corresponding value in cell A2 is returned only if it’s a
number.
¾ Solution:
Use the TEXT, TRIM, and SUBSTITUTE functions as shown in the
following formula:
=TEXT(TRIM(SUBSTITUTE(SUBSTITUTE(A2,")",""),"(","")),"General").
Explanation:
The nested SUBSTITUTE function returns the text in cell A2 after having
replaced the parentheses with nothing.
The TRIM function removes any redundant spaces from the text returned
by the SUBSTITUTE function.
The TEXT function sets the format of the string returned by the TRIM
function to "General".
¾ Solution:
Use the VALUE function as shown in the following formula:
=VALUE(B2)
Explanation:
The VALUE function converts the contents of cell B2 to a number.
Thus removing the apostrophe from the original value.
Subdividing Text
Subdividing a Mixed String into Separate Cells
Containing only Numbers or Characters
¾ Problem:
The strings in column A can be composed of both numbers and
characters; however, the numbers may only appear at the beginning of
the string and the characters at the end.
We want to separate the strings into two columns, one containing only
numbers and the other containing characters.
¾ Solution:
Use the LEFT, MAX, IF, ISNUMBER, MID, INDIRECT, and ROW
functions as shown in the following Array formula entered in column B:
{=LEFT(A2,MAX(IF(ISNUMBER(--
MID(A2,ROW(INDIRECT("1:1024")),1)),ROW(INDIRECT("1:1024")))))}
Then use the SUBSTITUTE function as shown in the following formula
entered in column C:
=SUBSTITUTE(A2,B2,"")
Explanation:
) Extracting Numbers:
The ROW, INDIRECT, and MID functions are used to create an Array
consisting of each of the characters in the string stored in cell A2.
The IF function returns an Array containing the position of each
numeric character in the above Array (using the ISNUMBER function).
The MAX function returns the maximal value in that Array (i.e. the
position of the last number in the string).
The LEFT function extracts the leftmost characters from cell A2 up to
the position returned by the MAX function, i.e. the numeric portion of
the string.
) Extracting Text:
The SUBSTITUTE function searches cell A2 for the text stored in cell
B2 (the numeric part of cell A2 returned by the first formula), and
replaces it with nothing.
Thus, only the character portion of the original string is returned.
¾ Solution:
Use the LEFT, MID, RIGHT, and FIND functions as shown in the
following formulas:
To extract the City: =LEFT(A2,FIND(",",A2)-1)
To extract the State: =MID(A2,FIND(",",A2)+2,2)
To extract the Zip code: =RIGHT(A2,5)
Explanation:
) City Formula:
The FIND function returns the position of the comma within the string
stored in cell A2.
The LEFT function extracts the leftmost characters up to the character
to the left of the comma (the position returned by the FIND function
minus 1), i.e. the City part of the address.
) State Formula:
The FIND function returns the position of the comma within the string
stored in cell A2.
The MID function returns the two characters to the right the comma
(the position returned by the FIND function plus 2), i.e. the State part
of the address.
) Zip Code Formula:
The RIGHT function extracts the 5 rightmost characters of the string
stored in cell A2, i.e. the Zip Code.
¾ Solution:
To retrieve the first name use the LEFT and FIND functions as shown in
the following formula:
=LEFT(A2,FIND(" ",A2))
To retrieve the last name use the RIGHT, LEN, and FIND functions as
shown in the following formula:
=RIGHT(A2,LEN(A2)-FIND(" ",A2))
Explanation:
) First Name Formula:
The FIND function returns the position of the space within the full
name stored in cell A2.
The LEFT function extracts the leftmost characters up to the position
returned by the FIND function, i.e. the first name.
) Last Name Formula:
The FIND function returns the position of the space within the full
name stored in cell A2.
The LEN function returns the number of characters in the full name.
The number of characters to the right of the space (i.e. the number of
characters in the last name) is calculated by subtracting the number
that represents the position of the space (returned by the FIND
function) from the length of the name (returned by the LEN function).
The RIGHT function extracts as many characters as calculated above,
starting at the rightmost character, i.e. the last name.
¾ Solution:
Use the TRIM, LEFT, FIND, and SUBSTITUTE functions as shown in the
following formula:
=TRIM(LEFT(A2,FIND("^",SUBSTITUTE(TRIM(A2)&" "," ","^",3))-1))
Explanation:
The following expression removes any redundant spaces from the text in
cell A2, and adds a space at the end of it: TRIM(A2)&" "
The SUBSTITUTE function returns the string created above after having its
3rd space replaced by the "^" symbol.
The FIND function returns the position of the "^" sign within that string.
The LEFT function extracts the leftmost characters in the string up to the
"^" sign (the position returned by the FIND function minus 1), i.e. the first
three words.
The TRIM function removes any redundant spaces from the text returned
by the LEFT function.
Replacing Characters
Creating New IP Addresses
¾ Problem:
Creating new IP addresses composed of the first three original segments
coupled with the last original segment multiplied by two.
¾ Solution:
Use the LEFT, FIND, and MID functions as shown in the following
formula:
=(LEFT(A2,FIND(".",A2,FIND(".",A2,FIND(".",A2)+1)+1)))&(MID(A2,
FIND(".",A2,FIND(".",A2,FIND(".",A2)+1)+1)+1,99)*2)
Explanation:
The nested FIND functions are used to calculate the position of the last "."
in the IP address stored in cell A2.
The LEFT function extracts all the characters to the left of that position
(i.e. the first three segments of the address).
The MID function extracts 99 characters starting with the position
calculated by the FIND function plus 1 (i.e. the last segment in the
address).
Finally, the last segment is multiplied by 2 and joined with the first three
segments of the original address.
We want to convert all the numbers with trailing minus signs to normally-
signed negative numbers.
¾ Solution:
1. Use the RIGHT and SUBSTITUTE functions as shown in the following
formula in column B:
=IF(RIGHT(A2,1)="-",SUBSTITUTE(A2,"-","")*-1,A2)
2. Use the VALUE, IF, RIGHT, LEFT, and LEN functions as shown in the
following formula in column C:
=VALUE(IF(RIGHT(A2,1)="-",RIGHT(A2,1)&LEFT(A2,LEN(A2)-1),A2))
Explanation:
) First Formula:
The RIGHT function extracts the rightmost character of the value in
cell A2.
If that character is a minus sign, the IF function returns the result of
the following expression:
SUBSTITUTE(A2,"-",")*-1
The SUBSTITUTE function replaces the minus sign in cell A2 with
nothing. The value is then multiplied by -1, to create the proper
negative number.
If the rightmost character from cell A2 is not a minus sign, the IF
function returns the original value.
) Second Formula:
The RIGHT function extracts the rightmost character from cell A2.
If that character is a minus sign, the IF function returns a string
composed of that minus sign and the rest of the characters in cell A2,
extracted by the LEFT function (based on the string’s length,
calculated by the LEN function).
If the rightmost character from cell A2 is not a minus sign, the IF
function returns the original value.
The VALUE function converts the text returned by the IF function to a
number.
¾ Solution:
Use the LEFT, FIND, and MID functions as shown in the following
formula:
=LEFT(A2,FIND("XX",A2)-1)&B2&MID(A2,FIND("XX",A2)+2,255)
Explanation:
The LEFT function extracts the leftmost characters in cell A2 up to the
"XX" substring (based on its position within cell A2 calculated by the
FIND function).
The MID function extracts 255 characters from cell A2, starting one
character after the "XX" substring (the position calculated by the FIND
function plus 2).
The text returned by the LEFT and MID functions is concatenated on
either side of the number in cell B2, thus creating a new string in which
"XX" has been replaced.
¾ Solution:
Use the LEFT, FIND, and MID functions as shown in the following
formula:
=LEFT(A2,FIND("/",A2)-1)+10&MID(A2,FIND("/",A2),255)
Explanation:
The FIND function returns the position of the "/" symbol within the string
in cell A2.
The LEFT function extracts the leftmost characters up to the calculated
position minus 1 (i.e. the first number).
The MID function, in combination with the FIND function, extracts the
remaining characters of the string in cell A2 (i.e. the "/" symbol and the
right number).
Finally, the left number has 10 added to it and is then joined with the rest
of the original string.
Searching a String
Searching a String for a Matching Word from
another String
¾ Problem:
Determining whether the first word from each string in column A appears
within the corresponding string in the same row of column B.
¾ Solution:
Use the IF, ISNUMBER, FIND, and LEFT functions as shown in the
following formula:
=IF(ISNUMBER(FIND(LEFT(A2,FIND(" ",A2)-1),B2)),"1st Word Found","1st
Word Not Found")
Explanation:
The second FIND function returns the position of the first space in the
string stored in cell A2.
The LEFT function extracts the leftmost characters in that string up to the
calculated position minus 1 (i.e. the first word from cell A2).
The first FIND function returns the position of that first word within the
string stored in cell B2.
If the word is not found within that string, the function returns an error.
The ISNUMBER function determines whether or not the result of the
FIND function is a number (i.e. whether or not the word was found).
If the ISNUMBER function returns TRUE, the IF function returns the string
"1st Word Found". Otherwise, it returns the string "1st Word Not Found".
¾ Solution:
Use the CHAR, SMALL, and CODE functions as shown in the following
Array formula:
{=CHAR(SMALL(CODE(A2:A6),1))}
Explanation:
The CODE function returns an Array containing the numeric code (ASCII)
for each letter in column A.
The SMALL function returns the smallest number in that Array, which is
the ASCII code of the alphabetically lowest letter in List1.
The CHAR function returns the character specified by that particular
ASCII code.
¾ Solution:
Use the IF and ISERROR functions as shown in the following formula:
=IF(ISERROR(A2+0),"Text","Number")
Explanation:
The above formula is based on the assumption that performing a
calculation on a text value would result in an error.
Therefore, the value stored in A2 has a 0 added to it.
The ISERROR function determines whether or not the calculation results
in an error and returns TRUE/FALSE accordingly.
If TRUE is returned, the IF function returns the string "Text". Otherwise, it
returns the string "Number".
¾ Solution:
Use the IF, EXACT, UPPER, and LOWER functions as shown in the
following formula:
=IF(EXACT(A2,UPPER(A2)),"Upper
Case",IF(EXACT(A2,LOWER(A2)),"Lower Case","Upper and Lower Case"))
Explanation:
The UPPER function converts the name in cell A2 to uppercase.
The EXACT function determines whether or not the original name in cell
A2 and the name returned by the UPPER function are identical, and
returns TRUE/FALSE accordingly.
If TRUE is returned, the IF function returns the string "Upper Case".
Otherwise, it returns the result of the second IF function:
The LOWER function converts the name in cell A2 to lowercase.
The EXACT function determines whether or not the original name in cell
A2 and the name returned by the LOWER function are identical, and
returns TRUE/FALSE accordingly.
If TRUE is returned, the IF function returns the string "Lower Case".
Otherwise, it returns the string "Upper and Lower Case".
¾ Solution:
Use the ISNUMBER, RIGHT, and LEFT functions as shown in the
following formula:
=IF(ISNUMBER(-RIGHT(A2,1)),"End",IF(ISNUMBER(-
LEFT(A2,1)),"Beginning"))
Explanation:
The RIGHT function extracts the rightmost character of the string stored in
cell A2.
The "-" sign then converts that character, if representing a number, to a
negative number.
If that character does not represent a number, that conversion will result
in an error.
The ISNUMBER function determines whether or not the result of the
above conversion is a number (whether or not the rightmost character of
cell A2 represents a number).
If it does, the IF function returns the string "End".
Otherwise, the leftmost character of the string (extracted by the LEFT
function) is checked to see if it is a number (using the "-" sign to convert it
to a negative number and the ISNUMBER function determine whether or
not the result of that conversion is numeric). If so, the IF function returns
the string "Beginning".
¾ Solution:
For case sensitive results: Use the ISNUMBER and FIND functions as
shown in the following formula:
=ISNUMBER(FIND(A2,B2))
For case insensitive results: use the SEARCH and LEN functions as shown
in the following formula:
=SEARCH(A2,B2&A2)<LEN(B2)
Explanation:
) Case Sensitive Formula:
The FIND function retrieves the position of the string to find (cell A2)
within the corresponding string in cell B2.
If the string is not found within cell B2, the formula returns an error.
The ISNUMBER function determines whether or not the result of the
FIND function is a number (i.e. whether or not the string was found),
and returns TRUE/FALSE accordingly.
As the FIND function is case sensitive, this formula returns case
sensitive results.
) Case Insensitive Formula:
The SEARCH function retrieves the position of the string to find (cell
A2) within a string combining cells B2 and A2.
If that number is smaller than the length of the string in B2 (calculated
by the LEN function), the formula returns TRUE. Otherwise, it returns
FALSE.
As the SEARCH function is case insensitive, this formula returns case
insensitive results.
¾ Solution:
Use the IF, AND, LEFT, and MID functions as shown in the following
formula:
=IF(AND(LEFT(A2,1)="1", MID(A2,2,3)<>"800"),"Long Distance", "Not
Long Distance")
Explanation:
The LEFT function extracts the leftmost character in cell A2 (i.e. the first
digit of the dialed number).
The MID function extracts the three characters starting in the second
character in cell A2.
If the first digit extracted is equal to "1" and the next three digits extracted are
not equal to "800", the AND function returns TRUE. Else, it returns FALSE.
The IF function returns "Long Distance" for TRUE or "Not Long Distance"
for FALSE.
¾ Solution:
Use the CHAR, SMALL, CODE, and MID functions as shown in the
following formula:
=CHAR(SMALL(CODE(MID(A2,{1,2,3},1)),1))&CHAR(SMALL(CODE(MID(
A2,{1,2,3},2)),2))&CHAR(SMALL(CODE(MID(A2,{1,2,3},3)),3))
Explanation:
The MID function in the first CHAR function returns an Array consisting
of each of the three characters in cell A2.
The CODE function returns an Array containing a numeric code (ASCII)
for each of those characters.
The SMALL function returns the smallest code in that Array (i.e. the ASCII
code corresponding with the alphabetically lowest letter).
The CHAR function returns the character specified by that particular
code, which, in this case, is alphabetically the lowest letter in cell A2.
Similarly, the second and third CHAR functions return the second and the
third lowest letters in cell A2.
Finally, the letters returned by all the CHAR functions are joined into a
single sorted string.
¾ Solution:
Use the RIGHT, LEN, FIND, and LEFT functions as shown in the
following formula:
=RIGHT(A2,LEN(A2)-FIND(" ",A2))&" "&LEFT(A2,FIND(" ",A2)-1)
Explanation:
In order to calculate how many characters are contained in the second
word, the position of the space is calculated by the FIND function and
this is subtracted from the string’s length (returned by the LEN function).
To extract the second word, the RIGHT function extracts as many
characters as was calculated above from the right end of the string.
Based on the position calculated by the FIND function, the LEFT function
extracts all characters to the left of the space, i.e. the first word in the
string.
Finally, the second word and the first word are joined together and
separated with a space.
¾ Solution:
Use the ADDRESS, SUM, IF, MAX, ROW, and COLUMN functions as
shown in the following Array formula:
{=ADDRESS(SUM(IF(A2:D7=MAX(A2:D7),ROW(A2:D7))),SUM(IF(A2:D7
=MAX(A2:D7),COLUMN(A2:D7))))}
Explanation:
The first IF function determines whether or not a given value in Range1 is
equal to the maximum for that range (calculated by the MAX function).
It returns an Array containing the row number (calculated by the ROW
function) of the value in Range1 that matches the maximum value, and a
"FALSE" for every other value in Range1.
The first SUM function adds the values in that Array, thus returning the
row number of the maximum value in Range1.
Similarly, the second SUM function returns the column number
(calculated by the IF and COLUMN functions) of the maximum value in
Range1.
Finally, the ADDRESS function returns a text value, representing the cell
reference indicated by the row and column numbers returned by the two
SUM functions.
¾ Solution:
Use the SMALL, IF, and ROW functions as shown in the following Array
formula:
{=SMALL(IF($A$2:$A$8=$B$2,ROW($A$2:$A$8),99999),ROW()-
ROW($B$2)+1)}
Copy the formula down column C until 99999 is returned, which
indicates that no further matches were found.
Explanation:
The IF function determines whether or not a given value in column A
matches the lookup value in cell B2.
It returns an Array consisting of the row number (calculated by the ROW
function) of every matching value and the number "99999" for every non-
matching value.
The ROW functions, used as the Kth argument of the SMALL function,
return the position of the current cell within the result column (C).
The SMALL function returns the Kth smallest number in the Array
returned by the IF function.
Thus, the smallest number in the Array (the row number of the first match)
is returned into cell C2, the second smallest number in the Array (the row
number of the second match) into cell C3, and so on.
¾ Solution:
Use the MAX, IF, and ROW functions as shown in the following Array
formula:
{=MAX(IF($A$2:$A$15=C2,ROW($A$2:$A$15)))}
Explanation:
The IF function determines whether or not a given value in column A
matches the letter in cell C2.
It returns an Array containing the row number (calculated by the ROW
function) of the successful match, and a "FALSE" for each of the other
values in column A.
The MAX function returns the largest number in that Array, i.e. the row
number of the matching letter from column A.
Chapter 3
This chapter deals with many of the issues and problems that may be
encountered when using Date & Time formulas. It includes the following
sections:
) Date, page 72: This section covers techniques on entering dates
quickly into a cell and calculating the difference between dates by
day, month, quarter, and year. You will also learn how to calculate
the last day of a given month, a project end, a payment due date, and
more.
) Time, page 102: This section deals with techniques on entering time
values quickly, adding and subtracting times, converting times to
decimal values, calculating military time, calculating by time zone,
rounding time values, and more.
) Date & Time, page 125: This section contains formulas dealing with
dates & time, such as date & time stamps, converting date & time
from GMT to CST, separating date & time, and more.
) Wages, Shifts & Time Worked, page 135: This section covers
formulas on date & time that are used to calculate time sheets,
employee hours worked, shifts, sick leave, pay days, and more.
Date
Entering Dates Quickly
¾ Problem:
Entering dates quickly, without having to use delimiters to separate
month, day, and year.
¾ Solution 1:
Enter only the "day" part of the date and complete it by using the DATE,
YEAR, TODAY, and MONTH functions in the following formula:
=DATE(YEAR(TODAY()),MONTH(TODAY()),A2)
Thus, on entering "5", the formula will automatically create a date
representing the 5th of the current month in the current year.
¾ Solution 2:
Enter the entire date, without delimiters, and use the DATEVALUE, LEFT,
MID, and RIGHT functions as shown in the following formula to convert
it to a proper date:
=DATEVALUE(LEFT(D2,2)&"/"&MID(D2,3,2)&"/"&RIGHT(D2,2))
Thus, on entering "060705", the above formula will return "06/07/05".
¾ Solution:
To calculate the difference in days, use the DATEDIF function as
shown in the following formula:
=DATEDIF(A2,B2,"d")
To calculate the difference in weeks, use the INT function as shown
in the following formula:
=INT((B2-A2)/7)
To calculate the difference in months, use the DATEDIF function as
shown in the following formula:
=DATEDIF(A2,B2,"m")
To calculate the difference in years, use one of the following two
solutions:
Use the DATEDIF function as shown in the following formula:
=DATEDIF(A2,B2,"y")
OR
Use the YEAR, MONTH, AND, and DAY functions as shown in the
following formula:
=YEAR(B2)-YEAR(A2)-(MONTH(B2)<MONTH(A2))-
(AND(MONTH(B2)=MONTH(A2),DAY(B2)<DAY(A2)))
To calculate the number of months over years, use the DATEDIF
function as shown in the following formula:
=DATEDIF(A2,B2,"ym")
To calculate the number of days over years, use the DATEDIF
function as shown in the following formula:
=DATEDIF(A2,B2,"yd")
¾ Solution:
Use the DATE and WEEKDAY functions as shown in the following
formula:
=DATE(C2,1,3)-WEEKDAY(DATE(C2,1,3),1)+7*(B2-1)+A2
Explanation:
The DATE function returns the date of January 3rd, for the year listed in
cell C2.
The WEEKDAY function returns the day of the week (1-7) that
corresponds with that date.
The number returned by the WEEKDAY function, representing a number
of days, is subtracted from the date calculated by the DATE function.
To that date is added the number of days that result from the following
calculation (based on the day of the week and week number listed in
cells A2:B2):
7*(B2-1)+A2
The result is the date that corresponds to the year, week number, and day
of the week listed in cells A2:C2.
¾ Solution:
To calculate the date at the end of the current month, use the
EOMONTH and TODAY functions as shown in the following
formula:
=EOMONTH(TODAY(),0)
To calculate the date at the end of next month, use the EOMONTH
and TODAY functions as shown in the following formula:
=EOMONTH(TODAY(),1)
To calculate the date at the end of each month listed in column A,
use the DATE function as shown in the following formula:
=DATE(2005,A2+1,0)
Explanation:
) End of Current Month Formula (cell D5)
The TODAY() function returns today’s date.
The EOMONTH function calculates the date 0 months after the date
returned by the TODAY function, and returns the last day of the
month for that date.
Thus, it returns the last day of the current month.
) End of Next Month Formula (cell D8)
The TODAY() function returns today’s date.
The EOMONTH function calculates the date 1 month after the date
returned by the TODAY function, and returns the last day of the
month for that date.
Thus, it returns the last day of the next month.
) DATE Formula (column B)
The DATE function calculates the date on day number 0 of the month
following the month listed in cell A2 (A2+1), for the year 2005.
As day number 0 indicates the last day of the previous month, the
DATE function returns the date of the last day of the month specified
in cell A2.
¾ Solution:
Use the NETWORKDAYS function as shown in the following formula:
=NETWORKDAYS(A2,B2)
Explanation:
The NETWORKDAYS function returns the number of whole workdays
between the dates entered in cells A2 and B2.
¾ Solution:
Use the WORKDAY and ROUNDUP functions as shown in the following
formula:
=WORKDAY(A2,ROUNDUP(B2/$C$2,0))
Explanation:
The number of required hours (cell B2) is divided by the number of daily
working hours (cell C2) and the ROUNDUP function rounds the result up
to the nearest integer (0 decimal places). Thus, it returns the number of
workdays required to complete the project.
The WORKDAY function calculates the date that is the number of
workdays after the project’s start date (cell A2) as was calculated by the
ROUNDUP function.
Thus, it returns the end date for the project in cells A2:B2.
¾ Solution:
Use the MIN and IF functions as shown in the following formula:
=MIN(IF(B2<>"",B2-3,C2-5),IF(C2<>"",C2-5,B2-3))
Explanation:
The first IF function determines whether or not cell B2 is blank. If it isn’t,
it subtracts 3 days from the test date stored in cell B2 and returns the
result. Otherwise, it subtracts 5 days from the paper deadline stored in
cell C2 and returns the result.
¾ Solution:
Use the IF, MOD, and TODAY functions as shown in the following
formula:
=IF(MOD(TODAY()-B2,14)=0,"Pay Today","")
Thus, the string "Pay Today" will appear next to each client whose
payment is due today.
Explanation:
The TODAY() function returns today’s date.
The date stored in cell B2 (the last pay date) is then subtracted from
today’s date, returning the number of days since the last pay date.
The MOD function divides that number of days by 14 and returns the
remainder.
If the remainder is 0 (the number of days since the last pay date is
divisible by 14), the IF function returns the string "Pay Today". Otherwise,
it returns a blank cell.
Thus, the formula indicates the clients who have payments due today.
¾ Solution:
Use the WEEKDAY and DATE functions as shown in the following
formula:
=DATE($B$2,A2,1+((1-(6>=WEEKDAY(DATE($B$2,A2,1),2)))*7+(6-
WEEKDAY(DATE($B$2,A2,1),2))))
Explanation:
The DATE function in the following expression calculates the date on the
first day of the month listed in cell A2 for the year specified in cell B2:
6>=WEEKDAY(DATE($B$2,A2,1),2)
The WEEKDAY function returns a serial number between 1 (Monday) & 7
(Sunday) that represents the day of the week matching that date.
Thus, it returns the day of the week on the first day of the month listed in
cell A2.
If that day is smaller than or equal to 6 (represents Saturday), the above
expression returns "1" (TRUE). Otherwise, it returns "0" (FALSE).
The value returned is subtracted from 1 and the result is multiplied by 7.
¾ Solution:
Use the MAX function as shown in the following formula:
=MAX(B2-A2,0)
Explanation:
The date in cell A2 is subtracted from the corresponding deadline in cell
B2 and the number of days between them is returned.
If the date in cell A2 is later than the deadline, a negative number of days
is returned.
The MAX function returns the maximum of the calculated number of days
and 0.
Thus, if the date in cell A2 is later than the corresponding deadline, the
formula returns zero, rather than a negative number of days.
¾ Solution:
Use the MAX, MIN, and DATE functions as shown in the following
formula:
=MIN(B2,DATE(2005,12,31))-MAX(A2,DATE(2005,1,1))
Explanation:
The first DATE function returns the date of December 31st, 2005 (the last
day of the year).
The MIN function returns the minimum of the date stored in cell B2 and
that returned by the DATE function.
Thus, if cell B2 is empty, the MIN function returns the last day of the year.
The second DATE function returns the date of January 1st, 2005 (the first
day of the month).
The MAX function returns the maximum of the date stored in cell A2 and
that returned by the DATE function.
Thus, if cell A2 is empty, the MAX function returns the first day of the
year.
Finally, the date returned by the MAX function is subtracted from the one
returned by the MIN function.
The result is the number of days between the pair of dates in cells A2 &
B2.
As the formula considers empty cells in column A as the first day of the
year, and empty cells in column B as the last day of the year, negative
results are never returned.
¾ Solution 1:
To avoid any format related problems, use the COUNTIF and DATE
functions as shown in the following formula:
=COUNTIF(A2:A6,">"&DATE(2005,4,1))
¾ Solution 2:
Use the COUNTIF function as shown in the following formula:
=COUNTIF(A2:A6,">"&--"2005-04-01")
Explanation:
The date entered in the above formula was considered by Excel to be
January 4th, rather than April 1st.
The manner in which Excel reads dates is dependant of the date format
set in the software’s regional settings.
Other regional areas use different date formats to that used in the United
States.
The two solutions provided above will return the proper results for any
date format set in the software.
) Solution 1:
The DATE function returns the date of April 1st, 2005.
The COUNTIF function returns the number of dates in column A
(cells A2:A6) that are greater than the date returned by the DATE
function.
Thus, it returns the number of dates in column A after April 1st, 2005.
) Solution 2:
The string "2005-04-01" represents the date of April 1st, 2005.
The "--" sign converts that string to the date it represents.
The COUNTIF function returns the number of dates in column A
(A2:A6) that are greater than that date.
Thus, it returns the number of dates in column A after April 1st, 2005.
¾ Solution:
Use the WEEKNUM function as shown in the following formula:
=WEEKNUM(A2,2)
Explanation:
The WEEKNUM function returns the week number corresponding with
the date stored in cell A2.
The second argument of the WEEKNUM function represents week type:
use "2" for a Monday-Sunday week, and "1" for a Sunday-Saturday week.
¾ Solution:
Use the WEEKNUM and IF functions as shown in the following formula:
=IF(WEEKNUM(A2,2)=WEEKNUM(B2,2),"Same Week","Different Week")
Explanation:
The first WEEKNUM function returns the week number corresponding
with the date stored in cell A2.
The second WEEKNUM function returns the week number corresponding
with the date stored in cell B2.
If the two week numbers are equal, the IF function returns the string
"Same Week". Otherwise, it returns "Different Week".
¾ Solution:
Use the DAY and DATE functions as shown in the following formula:
=DAY(DATE(B2,A2+1,0))
Explanation:
The DATE function calculates the date on day number 0 of the month
following the month listed in cell A2 (A2+1) for the year specified in cell
B2.
As day number 0 indicates the last day of the previous month, the DATE
function returns the date of the last day of the month specified in cell A2.
The DAY function extracts the "day" part of the date calculated by the
DATE function.
Thus, it returns the number of days in the month listed in cell A2 for the
year specified in cell B2.
¾ Solution:
Use the WEEKDAY and DATE functions as shown in the following
formula:
=WEEKDAY(DATE(2004,A2+1,0),2)
Thus, the formula will return a number between 1 & 7 for each month in
column A, where 1 represents Monday, and 7 represents Sunday.
To return 1 for Sunday and 7 for Saturday, modify your formula as
follows:
=WEEKDAY(DATE(2004,A2+1,0),1)
Explanation:
The DATE function calculates the date on day number 0 of the month
following the month listed in cell A2 (A2+1) for the year 2004.
As day number 0 indicates the last day of the previous month, the DATE
function returns the date of the last day of the month specified in cell A2.
The WEEKDAY function returns a number between 1 & 7 that represents
the day of the week that corresponds with the date calculated by the
DATE function. Thus, it returns the day of the week that corresponds with
the last day of the month specified in cell A2.
The second argument of the WEEKDAY function represents week type:
Use "2" for a Monday-Sunday week, where 1 represents Monday and 7
represents Sunday.
Use "1" for a Sunday-Saturday week, where 1 represents Sunday and 7
represent Saturday.
¾ Solution 1:
Use the DATE, YEAR, MONTH, MIN, and DAY functions as shown in the
following formula:
=DATE(YEAR(A2),MONTH(A2)+B2,MIN(DAY(A2),DAY(DATE(YEAR(A2),
MONTH(A2)+B2+1,0))))
¾ Solution 2:
Use the EDATE function as shown in the following formula:
=EDATE(A2,B2)
Explanation:
) DATE Formula
The DATE function in the following expression, using the YEAR and
MONTH functions, calculates the date of the last day in the month
that corresponds with the cumulative date.
MIN(DAY(A2),DAY(DATE(YEAR(A2),MONTH(A2)+B2+1,0)))
The DAY function (the second one in the expression) returns the day
part of that date, which is the number of days in the month of the
cumulative date.
The first DAY function in the above expression returns the day part of
the date in cell A2.
The MIN function returns the minimum of the numbers returned by
the two DAY functions.
Thus, the result of the above expression is the number to be used as
the day number of the cumulative date.
The YEAR function returns the year number of the date stored in cell
A2.
The MONTH function returns the month number (1-12) of the date
stored in cell A2.
The numbers of months specified in cell B2 is then added to that
number. The result represents the month number of the cumulative
date.
The DATE function returns the date that corresponds with the year
number returned by the YEAR function, the cumulative month
number, and the day number returned by the MIN function.
) EDATE Formula
The EDATE function returns the cumulative date for the date stored in
cell A2 and the number of months specified in cell B2.
¾ Solution 1:
To return a month’s full name, use the TEXT function as shown in the
following formula:
=TEXT(A2*29,"mmmm")
To return the first three letters of a month’s name ("Jan", "Feb" etc.), use
the TEXT function as shown in the following formula:
=TEXT(A2*29,"mmm")
¾ Solution 2:
Use the CHOOSE function as shown in the following formula:
=CHOOSE(A2,"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","
Nov","Dec")
Explanation:
) TEXT Formula
The month number in cell A2 is multiplied by 29.
The result is a number representing a date on that month.
The TEXT function formats that number as "mmmm" (a date format
displaying the name of the month) and converts it to text.
Thus, the formula converts the month number in cell A2 into its
corresponding name.
) CHOOSE Formula
The CHOOSE function returns the Nth value in the following list of
month names (entered in the formula), where N is the month number
stored in cell A2:
"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"
Thus, the formula converts the month number in cell A2 into its
corresponding name.
¾ Solution:
To calculate the quarter number based on a calendar year, use the INT
and MONTH functions in the following formula:
=INT((MONTH(A2)-1)/3)+1
To calculate the quarter number based on a fiscal year (starting in
September), use the MOD, CEILING, and MONTH functions as shown in
the following formula:
=MOD(CEILING(22+MONTH(A2)-9-1,3)/3,4)+1
Explanation:
) Formula for Quarter Number in a Calendar Year:
The MONTH function returns the month number (1-12) of the date
stored in cell A2.
1 is then subtracted from that number and the result is divided by 3.
The INT function rounds the result of that calculation down to the
nearest integer.
Finally, 1 is added to the number returned by the INT function.
The result is the quarter number matching the date stored in cell A2.
) Formula for Quarter Number in a Fiscal Year:
The MONTH function returns the month number (1-12) of the date
stored in cell A2.
1 and 9 are then subtracted from that number and 22 is added to the
result.
The CEILING function rounds up the result of that calculation to the
nearest multiple of 3.
The number returned by the CEILING function is divided by 3 and the
MOD function divides the result by 4 and returns the remainder.
Finally, 1 is added to that remainder.
The result is the quarter number matching the date stored in cell A2.
¾ Solution:
Use the MONTH, INT, and YEAR functions as shown in the following
formula:
="Quarter " &INT((MONTH(A2)+2)/3)&", "&YEAR(A2)
Explanation:
The MONTH function returns the month number (1-12) of the date stored
in cell A2.
2 is then added to that month number and the result is divided by 3.
The INT function rounds the result of that calculation down to the nearest
integer.
Thus, it calculates the quarter number matching the date stored in cell
A2.
The YEAR function returns the year number of the date stored in cell A2.
Finally, a single string is created by joining the text "Quarter ", the
calculated quarter number (returned by the INT function), the text "," and
the calculated year number (returned by the YEAR function).
Thus, the formula converts the date listed in cell A2 into a string
indicating the quarter number and year.
¾ Solution:
Use the CHOOSE, MATCH, and MONTH functions as shown in the
following formula:
=CHOOSE(MATCH(MONTH(A2),{1,4,7,10}),"Quarter1","Quarter2","Quar
ter3","Quarter4")
Explanation:
The MONTH function returns the month number (1-12) of the date stored
in cell A2.
The MATCH function returns the position of that number within the
following Array, consisting of the first month of each quarter:
{1,4,7,10}
If the number returned by the MONTH function does not appear in the
Array, the MATCH function returns the position of the closest smaller
match.
Thus, the MATCH function returns a number between 1 & 4.
The CHOOSE function returns the Nth value in the list of the strings
entered in the formula ("Quarter1","Quarter2","Quarter3","Quarter4"),
where N is the number returned by the MATCH function.
Hence, the formula determines which quarter the date in cell A2
corresponds with and returns a string indicating the result.
¾ Solution:
Use the DATE, YEAR, TODAY, MONTH, and DAY functions as shown in
the following formula:
=DATE(YEAR(TODAY()),MONTH(A2),DAY(A2))
Explanation:
The TODAY function returns today’s date.
The YEAR function returns the year number of that date, which is the
number of the current year.
The DATE function returns a date composed of the number of the current
year (returned by the YEAR function), the month of the date stored in cell
A2 (returned by the MONTH function), and the day of that date (returned
by the DAY function).
Thus, the formula converts the date stored in cell A2 into the
corresponding day and month of the current year.
¾ Solution:
Use the LEFT, IF, and MOD functions as shown in the following formula
and format the results as dates:
=("1/1/"&(IF(LEFT(A2,2)*1<20,2000,1900)+LEFT(A2,2)))+MOD(A2,1000)-1
Explanation:
The first LEFT function in the following expression extracts the two
leftmost characters of the Julian date stored in cell A2:
("1/1/"&(IF(LEFT(A2,2)*1<20,2000,1900)+LEFT(A2,2)))
Those characters (the "YY" part of the date) are then multiplied by 1 to
convert them to a number.
The IF function returns 2000 if that number is smaller than 20 and 1900 if
it isn’t.
The number returned by the IF function is added to the "YY" number
extracted by the LEFT function (the second one), and the result is the year
number indicated by the "YY" part of the Julian date in cell A2.
The text "1/1/" is joined with the calculated year number into a single
string that represents the date of the first day in that year.
The MOD function divides the Julian date stored in cell A2 by 1000, and
returns the remainder.
Thus, it returns the "JJJ" part of the Julian date, which is the serial number
of the day within the year.
Finally, 1 is subtracted from that number (representing a number of days),
and the result is added to the date calculated above (the first day of the
year represented by "YY").
The result is the calendar date corresponding with the Julian date stored
in cell A2.
Time
Entering Times Quickly (1)
¾ Problem:
Entering times quickly, without having to use a colon to separate hours
and minutes.
¾ Solution:
Use the TIMEVALUE, IF, LEFT, and RIGHT functions as shown in the
following formula:
=TIMEVALUE(IF(A2<1000, LEFT(A2,1),LEFT(A2,2))&":"&RIGHT(A2,2))
Enter the above formula in column B and format the cells as "hh:mm".
The formula will convert each numerical value in column A to a properly
formatted time value.
Explanation:
The IF function determines whether or not the numerical value in cell A2
is smaller than 1000.
If it is (the hour part of the entry consists of 1 digit), it returns the result of
the first LEFT function, which extracts the leftmost character of the
number in cell A2 (the digit representing the hour). Otherwise, it returns
the result if the second LEFT function, which extracts the two leftmost
characters of the number (the two digits representing the hour).
The hour part of the number in cell A2, returned by the IF function, is
then joined with the ":" symbol and with the minute part of the number,
which is extracted by the RIGHT function (extracts the two rightmost
characters of the number in cell A2).
Thus, a string representing the time indicated in cell A2 is returned.
Finally, the TIMEVALUE function converts that string to a time value.
¾ Solution:
To join minutes and seconds, use the TIME and INT functions as shown
in the following formula:
=TIME(,A2,B2)+INT(A2/1440)
Enter the above formula in column C and format as "[mm]:ss".
To join hours and minutes, use the TIME and INT functions as shown in
the following formula:
=TIME(E2,F2,) + INT(E2/24)
Enter the above formula in column G and format as "[hh]:mm".
The above formulas will allow the user to enter times quickly, without
having to use a colon to separate hours and minutes or minutes and
seconds.
Explanation:
Formula for Joining Hours and Minutes (cell G2):
The TIME function returns a time value composed of the number of hours
in cell E2 and the number of minutes in cell F2.
If the number of hours in cell E2 represents a time period of more than a
day (it is greater than 24), the TIME function will divide it by 24 and use
the remainder as the number of hours.
Thus, in order to create a time value that properly represents an hour
value greater than 24, we would have to calculate the number of full days
included in it and add it to the time calculated by the TIME function.
To calculate the number of full days represented by the hour value in cell
E2, it is divided by 24 and the INT function rounds the result down to the
nearest integer.
The time returned by the TIME function is added to the number of full
days calculated by the INT function.
The result is a time value (hh:mm) that represents the number of hours
and minutes listed in cells E2 & F2.
Using the same method, the formula entered in cell C2 calculates the
time value (mm:ss) that represents the number of minutes and seconds
listed in cells A2 & B2.
Both formulas allow the user to enter times quickly, without having to use
a colon to separate hours and minutes or minutes and seconds.
¾ Solution:
Excel’s default time format does not allow a time value to exceed 24
hours. This is the cause of the above error.
To properly display a sum exceeding 24 hours, change the format of the
cell from "h:mm" to "[hh]:mm".
¾ Solution:
Use the SUM and TIMEVALUE functions as shown in the following Array
formula:
{=SUM(TIMEVALUE(A2:A5))}
Explanation:
The TIMEVALUE function converts each string in cells A2:A5 to a time
value and returns the results in an Array.
The SUM function adds all the time values in that Array.
Thus, it returns the sum of the text values from column A that represent
times.
¾ Solution:
Use the SUM and TIME functions as shown in the following Array
formula:
{=SUM(TIME(A2:A4,B2:B4,0))}
Explanation:
The TIME function creates a time value from each corresponding pair of
hour and minute values from columns A (cells A2:A4) and B (cells B2:B4).
All the time values created are returned in an Array and the SUM function
adds them together.
The result is a cumulative time value of the hour and minute values listed
in columns A & B.
¾ Solution:
When adding a time value and a number representing hours, we must first
divide the number by 24, as shown in the following formula:
=A2+B2/24
Ensure that the result cell is formatted [hh]:mm to correctly display a time.
¾ Solution 1:
Use the IF function as shown in the following formula:
=IF(B2>=A2,B2-A2,A2-B2)
¾ Solution 2:
Use the ABS function as shown in the following formula:
=ABS(B2-A2)
Explanation:
) IF Formula:
The IF function determines whether the time value in cell B2 is later
than (or equal to) that in cell A2.
If it is, the IF function subtracts the time in cell A2 (the earlier time)
from that in cell B2 and returns the result.
Otherwise, it subtracts the time value in cell B2 (the earlier time) from
that in cell A2 and returns the result.
Thus, the formula always subtracts the earlier time from the later one,
regardless of which column each is in.
) ABS Formula:
The time value in cell A2 is subtracted from the corresponding time
value in cell B2.
The ABS function returns the absolute value of the result.
Thus, it returns the absolute difference between the time values in
cells A2 and B2.
That difference is equivalent to the difference between the later time
and the earlier time.
Subtracting Times
¾ Problem:
Finding the interval between each pair of start and end times in columns
A & B. An error occurs when the end time is "earlier" than the start time,
resulting in a negative result.
¾ Solution:
Use the IF function as shown in the following formula to determine which
of the two values is the "earliest", and then subtract accordingly:
=B2-A2+IF(A2>B2,1)
Explanation:
The IF function determines whether or not the End Time in cell B2 is
earlier than the corresponding Start Time.
If it is, the IF function returns 1. Otherwise, 0 is returned.
The Start Time in cell A2 is subtracted from the corresponding End Time
in cell B2, and the number returned by the IF function (1/0) is added to
the result.
Thus, if the End Time is earlier than the Start Time, 1 (representing a full
day) will be added to the negative difference, converting it to a positive
difference.
Hence, the formula calculates the interval between the dates in cells A2
& B2, without resulting in an error caused by a negative result.
¾ Solution:
Divide each number by 24 as follows:
=A2/24
Format your result cells as custom "[hh]:mm".
Explanation:
Time values are stored in Excel as fractions of 24 (01:00 is stored as 1/24).
Therefore, in order to convert the decimal value stored in cell A2 to a
time value ("hh:mm"), we must divide it by 24 and format the result as
time ("[hh]:mm").
¾ Solution:
Use the LEFT, FIND, LEN, and MID functions as shown in the following
formula:
=(LEFT(A2,FIND("m",A2)-1)*60)+LEFT(MID(A2,FIND("
",A2)+1,99),LEN(MID(A2,FIND(" ",A2)+1,99))-1)
Explanation:
The first LEFT function extracts the leftmost characters in cell A2 up to the
character "m" (based on the position calculated by the FIND function).
Those characters are then multiplied by 60, which returns the total
number of seconds indicated by the "minutes" ("X") part of the string.
The second LEFT function, using the MID, FIND, and LEN functions,
extracts all the characters in cell A2 from the character to the right of the
space up to the character that is second last, i.e. the "seconds" ("Y") part
of the string.
The two results are then added to give the total number of seconds.
¾ Solution:
Use the HOUR and MINUTE functions as shown in the following
formula:
=HOUR(A2)+(MINUTE(A2)/60)
Explanation:
The HOUR function returns the number of hours in the time value stored
in cell A2.
Similarly, the MINUTE function returns the number of minutes in that
time value.
¾ Solution 1:
Use the TEXT function as shown in the following formula:
=(TEXT(B2,"00\:00")-TEXT(A2,"00\:00"))*24
¾ Solution 2:
Use the DOLLARDE function as shown in the following formula:
=DOLLARDE(B2/100,60)-DOLLARDE(A2/100,60)
Explanation:
) TEXT Formula:
The first TEXT function formats the military time in cell B2 as "00\:00"
(a text value representing time).
The second TEXT function formats the military time in cell A2 in the
same manner. The second result is subtracted from the first, resulting
in a time value that represents the difference between the two military
times.
That difference is multiplied by 24 to convert it to its decimal
equivalent.
) DOLLARDE Formula:
The military time in cell B2 is divided by 100.
The first DOLLARDE function converts the result, which is a fraction
of 60, to its decimal equivalent.
Thus, it returns a decimal number that is equivalent to the military
time in cell B2.
Similarly, the second DOLLARDE function calculates the decimal
equivalent of the military time in cell A2.
The second number is subtracted from the first, resulting in the
interval between the military times in cells A2 & B2.
¾ Solution:
With destinations in cells C1:E1 and time differences in cells C2:E2, enter
the following formula in cell C3, and copy across to cell E3:
=$B$3+(C2/24)*-1
Explanation:
The hour difference in cell C2 is divided by 24 to convert it to a time
value.
The result is then multiplied by -1 to calculate the time that needs to be
added to the local time.
Finally, that time is added to (or subtracted from) the local time shown in
cell B3.
¾ Solution:
1. Create a list of cities (column A) and their matching hourly difference
(column B) from GMT (Greenwich Mean Time).
2. Use the VLOOKUP function as shown in the following formula in cell
D5:
=(D2*24-VLOOKUP(C2,A2:B8,2,FALSE)+VLOOKUP(C5,A2:B8,2,FALSE))/24
Explanation:
The first VLOOKUP function in the above formula looks in the first
column of range A2:B8 for the city entered in cell C2 (Jerusalem) and
returns the corresponding value from the second column.
Thus, it returns Jerusalem’s hourly difference with GMT.
Similarly, the second VLOOKUP function returns New York’s hourly
difference with GMT.
The time value in cell D2 (the time to convert) is multiplied by 24 to
convert it to its decimal equivalent.
¾ Solution 1:
Use the ROUNDDOWN function as shown in the following formula:
=ROUNDDOWN(A2*24*120,0)/(120*24)
¾ Solution 2:
Use the FLOOR function as shown in the following formula:
=FLOOR(A2,1/(24*120))
Explanation:
) ROUNDDOWN Formula:
The time value entered in cell A2 is multiplied by 24 to convert it to
its decimal equivalent, and by 120 to calculate the number of 30
second time periods within that time value (there are 120 periods of
30 seconds in an hour).
The ROUNDDOWN function rounds the result down to the nearest
integer (0 decimal places).
Finally, the decimal number returned by the ROUNDDOWN
function is divided by 120*24 in order to convert it back to a time
value.
Thus, the formula rounds the time in cell A2 down to the nearest 30
seconds.
) FLOOR Formula:
The FLOOR function rounds the number representing the time value
in cell A2 down to the nearest multiple of 1/(24*120). That multiple
represents a time value of 30 seconds.
Thus, it rounds the time in cell A2 down to the nearest 30 seconds.
¾ Solution:
Use the TIME, FLOOR, HOUR, and MINUTE functions as shown in the
following formula:
=TIME(HOUR(A2),FLOOR(MINUTE(A2),15),0)
Explanation:
The HOUR function returns the hour number of the time value stored in
cell A2.
Similarly, the MINUTE function returns minute number of that time value.
The FLOOR function rounds down that number of minutes to the nearest
multiple of 15.
Finally, the TIME function returns a time value composed of the hour
number returned by the HOUR function and the minute number
calculated by the FLOOR function.
Thus, the formula rounds down the time value stored in cell A2 to the
nearest 15 minute increment.
Rounding Hours Up
¾ Problem:
Listed in columns B & C are the times that each employee in column A
signed in and out of work today.
We want to calculate the number of hours each employee worked,
rounded up to the nearest hour.
¾ Solution:
Use the CEILING functions as shown in the following formula:
=CEILING((C2-B2)*24,1)
Explanation:
The Time Out in cell C2 is subtracted from the corresponding Time in cell
B2.
The result is a time value representing the difference between the two
times.
That time value is multiplied by 24 to convert it to its decimal equivalent,
and the CEILING function rounds the result up to the nearest multiple of
1 (the nearest integer, representing the nearest hour).
Thus, it returns the number of hours worked by the employee specified in
cell A2, rounded up to the nearest hour.
¾ Solution:
Use the ROUND function as shown in the following formula:
=ROUND((B2-A2)/"0:30:00",0)*"0:30:00"
Explanation:
The Time Out in cell B2 is subtracted from the corresponding Time In in
cell A2.
The result is a time value representing the difference between the two
times.
That time value is divided by a time value of 30 minutes ("0:30:00") in
order to calculate the number of 30 minute periods within that time.
The ROUND function rounds that number to the nearest integer (0
decimal places).
Finally, the number returned by the ROUND function is multiplied by a
time value of 30 minutes ("0:30:00"), returning a time value that
represents the interval between the Time In in cell A2 and the Time Out
in cell B2, rounded to the nearest 30 minutes.
¾ Solution:
Use the COUNTIF and COUNT functions as shown in the following
formula:
=(COUNTIF($C$2:$C$6,">="&E2)-COUNTIF($B$2:$B$6,">"&E2))/
COUNT($A$2:$A$6)
Explanation:
The first COUNTIF function returns the number of Time Out values in
column C (cells C2:C6) that are later than or equal to the Base Time in
cell E2.
Similarly, the second COUNTIF function returns the number of Time In
values in column B (cells B2:B6) that are later than the Base Time.
The number returned by the second COUNTIF function is then subtracted
from the number returned by the first COUNTIF function.
The result represents the number of tenants who were in the building at
the time specified in cell E2.
Finally, that number is divided by the total number of tenants in the
building, as calculated by the COUNT function (returns the number of
values in cells A2:A6).
The result is the building’s occupancy rate at the time listed in cell E2.
¾ Solution:
1. Go to Tools → Options → Calculation Tab → Check the Iteration
checkbox.
2. Use the IF and NOW functions as shown in the following formula:
=IF(A2=",",IF(B2="",NOW(),B2))
3. Apply "mm/dd/yyyy hh:mm" format to column B.
Explanation:
The first IF function determines whether or not cell A2 is blank. If it is, the
IF function returns a blank cell. Otherwise, it returns the result of the
second IF function.
The second IF function determines whether or not the current cell (cell
B2) is blank. If it is, the IF function returns the current date and time
¾ Solution:
Use the TIME function as shown in the following formula:
=A2-TIME(6,0,0)
Explanation:
The TIME function returns a time value of 6:00.
That time, representing the hourly difference between GMT and CST (6
hours), is then subtracted from the date and time value stored in cell A2.
The result is the CST equivalent of the GMT date and time shown in cell
A2.
¾ Solution:
Use the DATE and TIME functions as shown in the following formula:
=DATE(C2,A2,B2)+TIME(D2,E2,F2)
Format the results (column G) as "mm/dd/yy hh:mm:ss".
Explanation:
The DATE function returns a date composed of the year number in cell
C2, the month number in cell A2, and the day number in cell B2.
The TIME function returns a time composed of the hour number in cell
D2, the minute number in cell E2, and the second number in cell F2.
The resulting date and time are added and formatted as "mm/dd/yy
hh:mm:ss".
¾ Solution:
To extract dates, use the MID, LEFT, FIND, and SUBSTITUTE
functions as shown in the following formula:
=(--(MID(A2,5,2)&" "&LEFT(A2,3)&" "&MID(A2,FIND(" ",SUBSTITUTE(
A2," ","",1))+2,4)))
Enter the above formula in column B and format as "mm/dd/yyyy".
To extract times, use the MID, FIND, and SUBSTITUTE functions as
shown in the following formula:
=(--(MID(A2,FIND(" ",SUBSTITUTE(A2," ","",1))+7,255)))
Enter the above formula in column C and format as "h:mm PM/AM".
Explanation:
) Formula Extracting Dates:
The first MID function extracts two characters from the string in A2,
starting at the 5th character.
Thus, it returns the day number of the date.
The LEFT function extracts the three leftmost characters of the string in
cell A2.
Thus, it returns the three letters representing the name of the month.
The following expression, using the FIND and SUBSTITUTE
functions, calculates the position (character number) of the second
space in the string (the space before the year number):
FIND(" ",SUBSTITUTE(A2," ","",1))+2
The second MID function extracts 4 characters from the string in A2,
starting at the position calculated by the above expression.
Thus, it extracts the year number of the date.
The day number (returned by the first MID function), the month name
(returned by the LEFT function) and the year number (returned by the
second MID function) are joined into a single string with spaces
between them. That string represents the date in cell A2.
The "--" sign converts that string to a proper date value, and thus
returns the date in cell A2.
) Formula Extracting Times:
The SUBSTITUTE function returns the string in cell A2 after having its
first space removed (replaced by nothing).
The FIND function returns the relative position (character number) of
the first space in the string returned by the SUBSTITUTE function.
That position is equal to the position of the character in cell A2 that is
to the left of the second space in the string.
Adding 7 to that position returns the position of the first character in
the time part of the string.
The MID function extracts as many as 255 characters from cell A2,
starting at that calculated position.
Hence, it returns a string representing the time in cell A2.
The "--" sign converts that string to a proper time value, and thus
returns the time in cell A2.
¾ Solution:
Use the NETWORKDAYS and MOD functions as shown in the following
formula:
=NETWORKDAYS(A2,B2)-1-MOD(A2,1)+MOD(B2,1)
Explanation:
The NETWORKDAYS function returns the number of weekdays between
the date stored in cell A2 and the one in cell B2.
1 is subtracted from that number to exclude the date in cell B2 from the
number of weekdays.
The first MOD function divides the value in cell A2 by 1 and returns the
remainder, which represents the time part of the date and time value in
cell A2. That time is then subtracted from the total time represented by
the calculated number of weekdays.
Similarly, the time part of the date and time value in cell B2 (returned by
the second MOD function) is added to the above total.
The result is a time value, formatted as "[hh]:mm", that represents the
weekday hours between the two date and time values in cell A2 & B2.
¾ Solution:
To extract dates, use the INT function as shown in the following
formula:
=INT(A2)
Enter the above formula in column B and format as "mm/dd/yyyy".
To extract times, use the MOD function as shown in the following
formula:
=MOD(A2,1)
Enter the above formula in column C and format as "h:mm".
Explanation:
Date and time values are stored in Excel as numbers, where the integer
part represents the date, and the fraction part represents the time.
) Formula Extracting Dates (Column B)
The INT function rounds the number representing the date and time
value in cell A2 down to the nearest integer.
Thus, it returns the date stored in cell A2.
) Formula Extracting Times (Column C)
The MOD function divides the number representing the date and time
value in cell A2 by 1, and returns the remainder (the fraction part of
the number).
Thus, it returns the time stored in cell A2.
¾ Solution:
Use the INDEX, MATCH, and TEXT functions as shown in the following
Array formula:
{=INDEX($B$2:$B$18,MATCH(TEXT(E$1,"mmddyyyy")&TEXT($D2,"hh:m
m"),TEXT($A$2:$A$18,"mmddyyyy")&TEXT($A$2:$A$18,"hh:mm"),0))}
Enter the above formula in cell E2, copy it down the column and across
to column G.
Explanation:
The first TEXT function formats the date in E1 as "mmddyyyy" and
converts it to text.
The second TEXT function formats the time in D2 as "hh:mm" and
converts it to text.
Those two text values are joined into a single string, representing the date
and time in E2 and D2.
Similarly, the following expression returns an Array consisting of the
string representing each date and time value in column A (A2:A18)
TEXT($A$2:$A$18,"mmddyyyy")&TEXT($A$2:$A$18,"hh:mm").
The format of each string in the Array is identical to the format of the
string created above.
The MATCH function returns the position of the string created above
(representing the date in E2 and the time in D2) within the Array.
If the string does not appear in the Array, it returns the #N/A error.
The INDEX function returns the value from B2:B18 (patient name) that is
stored in the position calculated by the MATCH function.
Thus, it returns the name of the patient whose appointment is on the date
stored in E1 and the time specified in D2.
If there is no appointment listed in columns A & B for the date and time in
E1 and D2, the formula returns the #N/A error.
To complete the matrix and return the patient name for each date & time
combination, copy the formula to range E2:G10 (the references of the
cells containing the date and time criteria will update accordingly).
¾ Solution:
Create 3 columns containing the following data:
Date (column A), Time In (column B), Time Out (column C).
In the 4th column (Number of Hours), enter the following formula:
=(C2-B2+(C2<B2))*24
To sum the total number of hours worked, use the SUM function as
shown in the following formula:
=SUM(D2:D7)
Explanation:
) Number of Hours Formula (cell D2):
The Time In in cell B2 is subtracted from the corresponding Time Out
in cell C2, returning a time value that represents the time worked for
the date in cell A2.
If that Time Out is earlier than its corresponding Time In, a negative
time value is returned.
The following expression returns "1" (TRUE) if the Time Out in cell C2
is earlier than its corresponding Time In (cell B2) and "0" (FALSE) if it
isn’t:
C2<B2
The number returned by the above expression (1/0) is then added to
the time value calculated above.
Thus, if the Time Out is earlier than the Time In, 1 (representing a full
day) will be added to the negative time value returned above, and a
positive time value will be returned.
Finally, the time value calculated above (time worked) is multiplied
by 24 to convert it to its decimal equivalent.
Thus, the number of hours worked for the date in cell A2 will be
returned.
) Total Hours Formula (cell D9):
The SUM function adds all the values in the range cells D2:D9, which
consists of the number of hours worked for each date in column A.
We want to find the first time each employee logged in and the last time
they logged out.
¾ Solution:
To find the first login time for each unique ID in A13:A16, use the
MAX function as shown in the following Array formula:
{=1/MAX((A13=$A$2:$A$10)*($B$2:$B$10<>0)*(1/$B$2:$B$10))}
To find the last logout time for each unique ID in D13:D16, use the
MAX function as shown in the following Array formula:
{=MAX(($A$2:$A$10=D13)*($D$2:$D$10))}
Explanation:
) First Login Time Formula (cell B13):
The following expression returns an Array consisting of "1" (TRUE) for
each ID in column A (A2:A10) that matches the ID entered in cell
A13, and "0" (FALSE) for every ID that doesn’t:
A13=$A$2:$A$10
The following expression divides 1 by the number representing each
Login Time in column B (B2:B10) and returns the results in a single
Array:
1/$B$2:$B$10
The corresponding values in the above Arrays are multiplied and an
Array containing the results is returned.
The MAX function returns the maximum value in that Array.
That value is the quotient of 1 divided by the number representing the
first Login Time of the ID in cell A13.
Finally, 1 is divided by the number returned by the MAX function,
returning the first Login Time of the ID entered in cell A13.
) Last Logout Time Formula (cell E13):
The following expression returns an Array consisting of "1" (TRUE) for
each ID in column A (A2:A10) that matches the ID entered in cell
D13, and "0" (FALSE) for every ID that doesn’t:
$A$2:$A$10=D13
Each value (1/0) in that Array, representing an ID in column A, is
multiplied by the number representing the corresponding Logout
Time in column D, and the products are returned in a single Array.
Thus, that Array includes the Logout time for every ID in column A
that matches the ID entered in cell D13, and "0" for every ID that
doesn’t.
The MAX function returns the maximum value in that Array.
Thus, it returns the last Logout Time of the ID entered in cell D13.
¾ Solution:
Use the TEXT and TRUNC functions as shown in the following formula
=TEXT(TRUNC(A2)+(B2-A2),"mm""/""dd""/""yy"" - ""hh"" Hrs ""mm"" Mins
""")
The above formula performs the desired time calculation and uses the
TRUNC function to return the relevant date.
Explanation:
The TRUNC function truncates the number representing the date and time
in cell A2 (Time In) to an integer.
Thus, it returns the date stored in cell A2.
The date and time value in cell A2 (Time In) is subtracted from the
corresponding date and time in cell B2 (Time Out), the difference
represents the time worked.
The date returned by the TRUNC function and the time calculated above
are joined into a single date and time value.
The TEXT function formats that date and time value as "mm""/""dd""/""yy""
- ""hh"" Hrs ""mm"" Mins """ and converts it to text.
Thus, it returns a string indicating the date and the time worked with
respect to the Time In and Time Out values in cells A2 & B2.
¾ Solution:
To determine whether a time represents signing in or out, enter the
CHOOSE, MAX, and ROW functions as shown in the following Array
formula in column D:
{=CHOOSE(MAX((A2=$A$2:$A$9)*(ROW()<>ROW($A$2:$A$9))*((B2&C
2)<($B$2:$B$9&$C$2:$C$9)))+1,"Time Out","Time In")}
Thus, "Time In" or "Time Out" will be displayed next to each time shown
in column C.
Then, to calculate the number of hours worked by each person, use the SUM
and IF functions as shown in the following Array formula in column E:
{=SUM(IF(D2="Time Out",(A2=$A$2:$A$9)*($D$2:$D$9="Time In")*(C2-
$C$2:$C$9),0))}
Thus, the number of worked hours will be displayed next to the "Time
Out" indicator matching each ID.
Explanation:
) Formula in Column D:
The following expression returns an Array consisting of "1" for every
row in the range that meets the following three conditions, and "0" for
every row that doesn’t:
(A2=$A$2:$A$9)*(ROW()<>ROW($A$2:$A$9))*((B2&C2)<($B$2:$B$
9&$C$2:$C$9))
1. Column A contains the same ID as in cell A2.
2. The date and time in columns B & C are later than those in cells
B2 & C2.
3. The number of the row is different to that of the current row (2).
The MAX function returns the maximum number in that Array (1/0).
If "0" is returned, it indicates that there isn’t another row in the range
that contains an earlier time for the ID in cell A2.
Thus, the time listed in the current row (2) is the Time In for the ID in
cell A2.
If "1" is returned, it indicates that, in a different row, there is an earlier
time for the ID in cell A2.
Thus, the time listed in the current row (2) is the Time Out for the ID
in cell A2.
The CHOOSE function returns the Nth string out of the two entered in
the formula ("Time Out","Time In"), where N is the number returned
by the MAX function plus1.
Thus, the formula determines whether the time in cell C2 represents
signing in or out, and returns a string indicating the result.
) Formula in Column E:
The IF function determines whether or not the string in cell D2 is
"Time Out". If it isn’t, it returns 0 (representing a 00:00 time value). If
it is, it returns the result of the following expression:
(A2=$A$2:$A$9)*($D$2:$D$9="Time In")*(C2-$C$2:$C$9)
The above expression calculates the difference between the time
value in cell C2 (Time Out) and the time value in column C that
meets the following two conditions:
1. Its corresponding string in column D is "Time In".
2. Its corresponding ID in column A is the same as that in cell A2.
Thus, it calculates the difference between the Time Out in cell C2 and
its matching Time In in column C. That difference represents the time
worked by the ID shown in cell A2.
The IF function returns the result of the above expression, which is an
Array consisting of the time worked, calculated for the time value in
column C meeting the above conditions, and a "0" for every other
time value in column C.
The SUM function adds all the values in the Array returned by the IF
function, and thus returns the calculated time worked.
Hence, the formula returns a 0:00 time value next to "Time In"
indicators in column D, and the time worked for each "Time Out"
indicator.
¾ Solution:
Use the COUNTIF function as shown in the following Formula:
=COUNTIF(B2:B8,"N")*9+COUNTIF(B2:B8,"H")*4
Explanation:
The first COUNTIF function counts the number of values in column B
that are equal to "N". The result is then multiplied by 9.
¾ Solution 1:
To calculate the number of hours worked per day, enter the following
formula in column D:
=B2-A2+(A2>B2)
Then calculate the pay per day by entering the following formula in
column E:
=C2*D2*24
Finally, use the SUM function as shown in the following formula to sum
the results from column E:
=SUM(E2:E7)
¾ Solution 2:
Use the SUM function as shown in the following Array formula:
{=SUM((B2:B7-A2:A7+(A2:A7>B2:B7))*24*C2:C7)}
Explanation to Solution 1:
) Worked Hours Formula (Column D):
The Time In in cell A2 is subtracted from the corresponding Time Out
in cell B2, returning a time value that represents the time worked for
that day.
If that Time Out is earlier than its corresponding Time In, a negative
time value is returned.
The following expression returns "1" (TRUE) if the Time Out in cell B2
is earlier than its corresponding Time In (A2) and "0" (FALSE) if it isn’t.
A2>B2
The number returned by the above expression is then added to the
time value calculated above.
Thus, if the Time Out is earlier than the Time In, 1 (representing a full
day) will be added to the negative time value returned above (the
difference), and a positive time value (time worked) will be returned.
) Pay per Day Formula (Column E):
The time worked, stored in cell D2, is multiplied by 24 to convert it to
its decimal equivalent.
Then, it is multiplied by the hourly rate in cell C2 to calculate the pay
for that day of work.
) Total Pay Formula (cell A10):
The SUM function adds the values in the range E2:E7, which consists
of the pay for each day of work.
Thus, it returns the total pay.
Explanation to Solution 2:
The following expression returns an Array consisting of the difference
between each Time Out in column B (cells B2:B7) and the corresponding
Time In from column A:
B2:B7-A2:A7
Thus, an Array of time values is returned, representing the time worked
on each day.
¾ Solution:
Use the WEEKDAY, MAX, and MIN functions as shown in the following
formula:
=IF(WEEKDAY(A2,2)<=5,MAX(D2-
8,0)*$C$11+MIN(D2,8)*$B$11,MAX(D2-8,0)*$C$12+MIN(D2,8)*$B$12)
Explanation:
The following expression calculates the pay for the worked hours in cell
D2, based on the weekday rate:
MAX(D2-8,0)*$C$11+MIN(D2,8)*$B$11
8 is subtracted from the number of worked hours in cell D2, in order to
calculate the number of overtime hours.
If the number of worked hours is smaller than 8 (no overtime), a negative
number is returned.
The MAX function returns the maximum of the calculated number of
overtime hours and 0.
¾ Solution:
Use the IF and TIME functions as shown in the following formula:
=IF(IF(B2<A2,B2+1-A2,B2-A2)>TIME(8,0,0),"Full Shift","Partial Shift")
Explanation:
The second IF function determines whether or not the Time Out in cell
B2 is earlier than its corresponding Time In in cell A2.
If it is, the IF function calculates the difference between cells B2 and A2
(the time worked) and adds 1 (representing a full day) to convert it from
negative to positive.
Otherwise, it simply calculates the difference between cells B2 and A2.
Thus, it returns a time value representing the time worked.
The TIME function returns a time value representing 8 hours (8:00).
The first IF function determines whether the time worked (returned by the
second IF function) is greater than 8 hours (returned by the TIME
function). If it is, the string "Full Shift" is returned. Otherwise, "Partial
Shift" is returned.
Thus, the formula determines the type of shift that corresponds with the
pair of time values in cells A2 & B2, and returns a string indicating the
result.
¾ Solution:
Use the IF and TIME functions as shown in the following formula:
=IF(A2<TIME(12,0,0),"Morning Shift",IF(A2<TIME(16,0,0),"Afternoon
Shift","Night Shift"))
Explanation:
The first TIME function returns the time value "12:00".
The first IF function determines whether or not the Time In in cell A2 is
earlier than 12:00.
If it is, the IF function returns the string "Morning Shift". Otherwise, it
returns the result of the second IF function.
¾ Solution:
Use the SUMPRODUCT and OFFSET functions as shown in the following
formula:
=SUMPRODUCT((OFFSET($A$3:$A$9,0,2*(B12-1))=A12)*(OFFSET
($B$3:$B$9,0,2*(B12-1))>8))
Explanation:
The first OFFSET function offsets column A (cells A3:A9) by as many
columns to the right as calculated by the following expression:
2*(B12-1)
The result of that expression represents the number of columns between
columns A and the ID column for the week specified in cell B12.
Thus, the OFFSET function returns the reference of the ID column for the
week specified in cell B12.
Every value (ID) in that column is compared with the ID entered in cell
A12. That comparison yields an Array consisting of "1" (TRUE) for each
value that matches that ID and "0" (FALSE) for each value that doesn’t.
Similarly, the second OFFSET function returns the reference of the Hours
column for the week specified in cell B12.
Every value (# Hours) in that column is compared with 8. That
comparison yields an additional Array consisting of "1" for each value that
is greater than 8 and "0" for each value that isn’t.
The SUMPRODUCT function adds the products of the corresponding
values (1/0) in the two Arrays created above.
The result represents the number of overtime shifts (i.e. over 8 hours) that
the employee shown in cell A12 worked in the week specified in cell B12.
¾ Solution:
Use the DAY, EOMONTH, and DATE functions as shown in the following
formula:
=DAY(EOMONTH(DATE(2005,A2,1),0))*24-(A2=4)+(A2=10)
Explanation:
The DATE function returns the date of the first day of the month specified
in cell A2, for the year 2005.
The EOMONTH function calculates the date 0 months after the date
returned by the DATE function, and returns the last day of the month per
that date. Thus, it returns the date of the last day of the month specified in
cell A2.
The DAY function returns the day part of that date, thus representing the
number of days in the month entered in cell A2.
That number of days is then multiplied by 24 to calculate the total
number of hours constituting the month in cell A2.
The following expression returns "1" (TRUE) if the month number in cell
A2 equals 4 (April) and "0" (FALSE) if it doesn’t:
A2=4
Similarly, the following expression returns "1" (TRUE) if the month
number in cell A2 equals 10 (October) and "0" (FALSE) if it isn’t:
A2=10
The result of the first expression (returning "1" for April), is subtracted
from the total number of hours calculated above, and the result of the
second expression (returning "1" for October) is added.
Thus, if the month in cell A2 is April (4), one hour is subtracted from the
total due to the shift to daylight saving time.
If the month is October (10) one hour is added due to the shift back to
standard time.
Thus, the formula calculates the number of hours in the month in cell A2,
allowing for daylight-saving shifts.
¾ Solution:
Use the SUM and TODAY functions in the Array formula:
{=SUM(((TODAY()-A2:A8)<=90)*(B2:B8=C2))}
Explanation:
The TODAY function returns today’s date.
The following expression returns an Array consisting of the difference
between today’s date and each date in column A (cells A2:A8):
TODAY()-A2:A8
Each value in that Array, representing the number of days between
today’s date and a particular date in column A, is compared with 90.
That comparison yields an Array consisting of "1" (TRUE) for every
number in the Array that is smaller than or equal to 90, and "0" (FALSE)
for every number that isn’t.
The following expression returns an additional Array consisting of "1"
(TRUE) for every value in column B (cells B2:B8) that matches the
absence type specified in cell C2 ("V") and "0" (FALSE) for every value that
doesn’t:
B2:B8=C2
The corresponding values (1/0) in the two Arrays created above are
multiplied and a single Array, consisting of the results, is returned.
The SUM function adds the values in that Array.
The result represents the number of vacation days in column B (absence
type ="V") that occurred during the last 90 days.
¾ Solution:
As time values in Excel are stored as fractions of 24 (an entire day), we
must first multiply the times in column B by 24 in order to convert them
to decimal values.
Hence, we calculate productivity as shown in the following formula:
=C2/(B2*24)
Chapter 4
Lookup
¾ Solution:
Use the INDIRECT and ADDRESS functions as shown in the following
formula:
=INDIRECT(ADDRESS(C2,D2))
Explanation:
The ADDRESS function returns a text value representing a cell reference
based on the row and column numbers in cells C2 & D2.
The INDIRECT function returns the data stored in the reference indicated
by that text value.
¾ Solution:
Use the INDIRECT, IF, MOD, and ROW functions as shown in the
following formula:
=INDIRECT(IF(MOD(ROW(),2)=0,"A"&ROW(),"B"&ROW()))
Explanation:
The ROW() function returns the row number of the current cell. The
MOD function then divides that number by 2 and returns the remainder.
If the row number is even (remainder=0), the IF function returns a string
composed of the letter "A" and the current row number.
Otherwise, it returns a string composed of the letter "B" and the current
row number.
Finally, the INDIRECT function returns the reference indicated by the
result of the IF function.
¾ Solution:
Use the INDIRECT function as shown in the following formula:
=INDIRECT("[Book1.xls]Sheet1’!"&A2&"")
Explanation:
The Workbook name, Sheet name, and Range name (entered in cell A2)
are joined into a single text value.
The INDIRECT function returns the reference indicated by that text value.
¾ Solution:
Use the VLOOKUP and INDIRECT functions as shown in the following
formula:
=VLOOKUP(B2,INDIRECT(C2),1,FALSE)
Explanation:
The INDIRECT function returns the range reference indicated by the text
value in cell C2 (Named Range).
The VLOOKUP function then looks in the first column of that range for
the value stored in cell B2 and returns it if a match is found.
¾ Solution:
Use the INDIRECT function as shown in the following formula:
=INDIRECT("’"&A2&" "&B2&"’!A1")
Explanation:
The first name (cell A2), last name (cell B2), and cell reference (cell A1)
are combined into a single string, which represents a sheet name and cell
reference to retrieve.
The INDIRECT function then returns the reference indicated by that text
value.
¾ Solution:
Use the INDIRECT and TEXT functions as shown in the following
formula:
=INDIRECT(TEXT(A2,"mmyy")&"’!A1")
Explanation:
The TEXT function formats the date in cell A2 to as "mmyy" and converts
it to a text value. That text is combined with the text "A1" to represent the
worksheet and cell reference to retrieve.
The INDIRECT function returns the reference indicated by that string.
¾ Solution:
Use the INDIRECT and COLUMN functions as shown in the following
formula:
=INDIRECT("Sheet" & COLUMN()-COLUMN($C$2)+1 & "’!$A$1")
Explanation:
The COLUMN functions return the column number of the current cell
(COLUMN()) and of cell C2 (COLUMN ($C$2)).
Those column numbers are then used to calculate a sheet number.
The text value "Sheet" is combined with the calculated sheet number and
the desired cell reference ("$A$1") to create a single string.
The INDIRECT function returns the reference indicated by that string.
¾ Solution:
To retrieve the values listed in column C in the range specified in column
A, use the VLOOKUP and INDIRECT function as shown in the following
formula:
=VLOOKUP(C2,INDIRECT("’"&$A$2&"\["&$A$5&".xls]"&$A$8&"’!"&$A
$11),2,FALSE)
Explanation:
Use the INDIRECT function to create a reference from the data in column A.
To refer to a range in a different workbook, use the following syntax in
the INDIRECT formula:
’Drive:\Folder\[WorkbookName.xls]SheetName’!Range
Note that the full path (Drive:\Folder\[WorkbookName.xls]SheetName) is
enclosed in single quotes and followed by the "!" sign, separating it from
the range.
The workbook name must be enclosed in brackets ("[]") and include the
".xls" ending.
All of these elements are required in order for INDIRECT to return the
proper information when referring to a different workbook.
(Drive and folder may be omitted if they are the same as those of the file
currently in use).
The following INDIRECT formula refers to the range specified in column A:
=INDIRECT("’"&$A$2&"\["&$A$5&".xls]"&$A$8&"’!"&$A$11)
The data in cells A2, A5, A8 & A11 is joined into a single string, which
represents a range reference in a different workbook.
The INDIRECT function returns the reference indicated by that string.
The VLOOKUP function looks for the value stored in cell C2 in the first
column (column A) of the range reference returned by the INDIRECT
function, and retrieves the corresponding value from the second column
(column B).
¾ Solution:
Use the IF and LOOKUP functions as shown in the following formula:
=IF(A2="Jeans",LOOKUP(B2,{"Diesel","Lee","Levis";85,70,80}),IF(A2="T-
Shirt",LOOKUP(B2,{"Gap","Old Navy","Sacks"},{5,3,7})))
Explanation:
Each LOOKUP function (one for each item type) searches in its respective
Array for the brand entered in cell B2 and returns the matching price.
Depending on the item type stored in cell A2, the IF functions determine
which of the two LOOKUP functions is used.
¾ Solution:
Use the INDEX function as shown in the following formula:
=INDEX($A$2:$A$6,B2)
Explanation:
The INDEX function returns the value from List1 at the position specified
in cell B2.
¾ Solution:
Use the INDEX, MATCH, and LARGE functions as shown in the following
formula:
=INDEX($A$2:$A$6,MATCH(LARGE($B$2:$B$6,A9),$B$2:$B$6,0))
Explanation:
The LARGE function returns the kth highest sales figure in cells B2:B6,
where kth is the rank specified in cell A9.
The MATCH function returns the position (row number) of that sales
figure within column B.
Finally, the INDEX function returns the name stored in the corresponding
position in column A.
¾ Solution:
Use the INDEX, MATCH, and MAX functions in the following formula:
=INDEX(A2:A9,MATCH(MAX(B2:B9),B2:B9,0))
Explanation:
The MAX function returns the maximum value in column B (cells B2:B9).
The MATCH function returns the position of that value within cells B2:B9.
Finally, the INDEX function returns the value stored in the corresponding
position in column A (cells A2:A9).
Thus, it returns the name of the player who scored the highest number of
points.
¾ Solution:
Use the INDEX and MATCH functions as shown in the following formula:
=INDEX($A$2:$A$6,MATCH(E2,$B$2:$B$6))
Explanation:
The MATCH function returns the position (row number within column B)
of the start page that is closest to (and smaller than) the page number in
cell E2.
The INDEX function returns the file name that is stored in the
corresponding position in column A.
¾ Solution:
Use the INDEX, MIN, IF, ABS, and ROW functions as shown in the
following Array formula:
{=INDEX($A$2:$A$6,MIN(IF(ABS($B$2:$B$6-D2)=MIN(ABS($B$2:$B$6-
D2)),ROW($B$2:$B$6)-ROW($B$2)+1)),1)}
Explanation:
The ABS function returns an Array containing the absolute differences
between each mark in column B and the mark to grade in cell D2.
The second MIN function returns the smallest number in that Array.
Thus, it calculates the minimal absolute difference between any mark in
column B and the mark to grade in cell D2.
The IF determines whether or not the difference between each mark in
column B and the mark entered in cell D2 equals that minimal difference,
and returns an Array of the row numbers (calculated by the ROW
function) of all the marks that satisfy that condition.
The MIN function then returns the smallest number in that Array, which is
the row number of the mark in column B that is closest to the one entered
in cell D2.
Finally, the INDEX function retrieves the grade from column A that is
stored in the position indicated by that row number.
Thus returning the grade that corresponds to the mark that is closest to the
one entered in cell D2.
¾ Solution:
Use the MODE and IF functions as shown in the following Array formula:
{=MODE(IF($A$2:$A$12=D2,$B$2:$B$12))}
Explanation:
The IF function returns an Array containing all the numbers in column B
having a corresponding value in column A that matches the criteria stored
in cell D2.
The MODE function returns the value within that Array that occurs most
frequently.
¾ Solution:
To find the last character for each row, use the HLOOKUP and REPT
functions as shown in the following formula in column H:
=HLOOKUP(REPT("z",10),B2:F2,1)
To find the last value (of any type) in each row, use the INDEX, MAX,
IF, and COLUMN functions as shown in the following Array formula
in column I:
{=INDEX(B2:F2,1,MAX(IF(B2:F2<>"",COLUMN(B2:F2)))-
COLUMN(B2)+1)}
Explanation:
) Last Character Formula:
The REPT function returns a string in which the letter "z" is repeated
10 times ("zzzzzzzzzz").
The HLOOKUP function then looks for that string in row 2 (cells
B2:F2), and returns the character closest to it within the row (i.e. the
last character in the row).
) Last Value Formula:
The IF function returns an Array consisting of the column numbers
(calculated by the COLUMN functions) of all the non-blank cells in
row 2 (cells B2:F2).
The MAX function returns the largest number in that Array (i.e. the
column number of the last non-blank cell in the row).
The INDEX function retrieves the value from row 2 that is stored in
the position indicated by that column number.
¾ Solution:
Use the OFFSET and COUNTA functions as shown in the following
formula:
=OFFSET(A1,COUNTA($A:$A)-1,0)
Note:
The formula will only work correctly when there are no empty cells
within the list.
Explanation:
The COUNTA function returns the number of values (non-blank cells) in
column A.
The OFFSET function offsets the reference "A1" as many rows as the
number calculated by the COUNTA function, minus 1.
Thus, the reference of the last non-blank cell in the column is returned.
¾ Solution:
Use the INDEX and MATCH functions as shown in the following Array
formula:
{=INDEX(A2:A7,MATCH(TRUE,A2:A7<>"",0))}
Explanation:
The MATCH function returns the position (row number) of the first cell in
Range1 for which "TRUE" is the result of the following expression:
A2:A7<>""
(i.e. the position of the first non-blank cell).
The INDEX function then returns the value from Range1 stored in that
position.
¾ Solution:
Use the MAX and IF functions as shown in the following Array formula:
{=MAX(IF($A$2:$A$8=D2,$B$2:$B$8))}
Explanation:
The IF function returns an Array containing the pay dates (column B)
corresponding to all the values in column A that match the client criteria
(cell D2).
The MAX function returns the maximum date within that Array.
¾ Solution:
To find the closest larger number or an exact match in column A, use
the SMALL and COUNTIF functions as shown in the following
formula:
=SMALL($A$2:$A$7,COUNTIF($A$2:$A$7,"<"&B2)+1)
To find the closest smaller number or an exact match in column A,
use the LARGE and COUNTIF functions as shown in the following
formula:
=LARGE($A$2:$A$7,COUNTIF($A$2:$A$7,">"&B2)+1)
Explanation:
) Formula for Closest Larger Value:
The COUNTIF function returns the number of values in column A
that are smaller than the lookup value in cell B2.
The SMALL function returns the kth smallest number in column A,
where kth is the number calculated by the COUNTIF function, plus 1.
) Formula for Closest Smaller Value:
The COUNTIF function returns the number of values in column A
that are larger than the lookup value in cell B2.
The LARGE function returns the kth largest number in column A,
where kth is the number calculated by the COUNTIF function, plus 1.
¾ Solution:
Use the INDEX and MATCH functions as shown in the following Array
formulas:
First greater value -
{=INDEX($A$2:$A$7,MATCH(TRUE,$A$2:$A$7>C2,0))}
First smaller value -
{=INDEX($A$2:$A$7,MATCH(FALSE,$A$2:$A$7>C2,0))}
Explanation:
) Formula for First Greater Value:
The MATCH function returns the position (row number) of the first
cell in column A for which "TRUE" is the result of the following
expression:
$A$2:$A$7>C2
(i.e. the first cell containing a value larger than the criteria in cell C2).
The INDEX function then returns the value from column A stored in
that position.
) Formula for First Smaller Value:
The MATCH function returns the position (row number) of the first
cell in column A for which "FALSE" is the result of the following
expression:
$A$2:$A$7>C2
(i.e. the first cell containing a value smaller than the criteria in cell C2).
The INDEX function then returns the value from column A stored in
that position.
¾ Solution:
To retrieve the maximal name within column A, use the INDEX,
MATCH, MAX, and COUNTIF functions as shown in the following
Array formula:
{=INDEX(A2:A8,MATCH(MAX(COUNTIF(A2:A8,"<"&A2:A8)),COUN
TIF(A2:A8,"<"&A2:A8),0))}
Explanation:
The COUNTIF function returns an Array containing the number of names
in column A that are smaller (based on alphabetic order) than each name
listed in the column.
The MAX/MIN function returns the largest/ smallest number in that array,
representing the largest/ smallest name.
The MATCH function then returns the position (row number) of that
number within the Array returned by the COUNTIF function.
Finally, the INDEX function returns the name from column A that is
stored in the row number returned by the MATCH function.
¾ Solution:
Use the INDEX, MATCH, and EXACT functions as shown in the following
Array formula:
{=INDEX($B$2:$B$7,MATCH(TRUE,EXACT(A11,$A$2:$A$7),0))}
Explanation:
The EXACT function checks whether the character in cell A11 is an exact
(case sensitive) match of any of the characters in cells A2:A7.
It then returns an Array of TRUE/FALSE results, one for each character in
cells A2:A7.
The MATCH function returns the position of the first "TRUE" within that
Array. (i.e. the position of the first character in cells A2:A7 that is an exact
match of the one in cell A11).
Finally, the INDEX function returns the code from column B that is stored
in the corresponding position.
¾ Solution:
To retrieve the minimal value use the SUBTOTAL function as shown
in the following formula:
=SUBTOTAL(5,B13:B21)
To retrieve the maximal value use the SUBTOTAL function as shown
in the following formula:
=SUBTOTAL(4,B13:B21)
Explanation:
The SUBTOTAL function returns a subtotal for a list or database.
To add a subtotal to a filtered list and ignore any hidden values, use the
numbers 1-11 as the first argument of the function (new from Excel
version 2003).
To include hidden numbers in your subtotal, use the numbers 101-111 as
the first argument.
The screenshot (Excel 2003 version) provides an explanation of the
various argument numbers that are available to be used in the SUBTOTAL
function.
¾ Solution:
Use the INDEX, SMALL, IF, and ROW functions as shown in the
following Array formula:
{=INDEX($B$2:$B$12,SMALL(IF($A$2:$A$12=C2,ROW($B$2:$B$12)-
ROW($B$2)+1),D2))}
Explanation:
The IF function returns an Array containing the positions (returned by
ROW function) of all the values in column A that are equal to the number
in cell C2.
The SMALL function returns the kth smallest number within that array,
where kth is the match number to retrieve (cell D2).
Finally, the INDEX function returns the value from column B that is stored
in the row number returned by the SMALL function.
¾ Solution:
Use the MAX, IF, MOD, and ROW functions as shown in the following
Array formula:
{=MAX(IF(MOD(ROW($A$2:$A$10)-ROW($A$2)+1,3)=0,$A$2:$A$10))}
Explanation:
The ROW functions are used to calculate the serial numbers matching
each value in List1, based on the row number of each value.
The MOD function divides each of those serial numbers by 3, and returns
the remainder.
The IF function returns an Array containing all the values in column A
which calculated serial numbers are divisible by 3 (i.e. an Array
containing every third value from List1).
The MAX function returns the largest value in that Array.
¾ Solution:
To retrieve the nth value in the column, use the OFFSET function as
shown in the following formula in column D:
=OFFSET($B$1,0,C4-1)
To retrieve the nth value in the row, use the OFFSET function as
shown in the following formula in column E:
=OFFSET($A$4,C4-1,0)
Explanation:
The OFFSET function returns a reference that is offset from the given
reference ($B$1/$A$4) by as many columns/rows as the number in cell
C4, minus 1.
¾ Solution:
Use the INDEX and ROW functions as shown in the following formula:
=INDEX($A$2:$A$13,(ROW()-2)*3+3)
Explanation:
The ROW() function returns the row number of the current cell.
That number is then used to calculate the next position (row number) that
is a multiple of 3.
The INDEX function returns the value in List1 that is stored in that
position.
¾ Solution:
Use the INDEX and MATCH functions as shown in the following formula:
=INDEX($A$1:$G$7,MATCH(A10,$A$1:$A$7,0),MATCH(B10,$A$1:$G$
1,0))
Explanation:
The first MATCH function (used as the row_num argument of the INDEX
function) returns the position (row number) of the origin (cells A1:A7)
entered in cell A10. The second MATCH function (used as the
column_num argument of the INDEX function) returns the position
(column number) of the destination (cells A1:G1) entered in cell B10.
The INDEX function retrieves the value from cells A1:G7 that is stored at
the intersection of the row and column numbers calculated by the
MATCH functions.
¾ Solution:
Use the INDEX and MATCH functions as shown in the following formula:
=INDEX($B$2:$B$7,MATCH(C2,$A$2:$A$7,0)+1)
Explanation:
The MATCH function returns the position (row number) in column A of
the lookup value (cell C2).
The INDEX function returns the letter in column B that is stored one row
down from that position.
¾ Solution:
Use the INDEX and MATCH functions as shown in the following Array
formula:
{=INDEX($C$3:$C$7,MATCH(A12&B12,$A$3:$A$7&$B$3:$B$7,0))}
Explanation:
The MATCH function looks in Range1 ($A$3:$A$7&$B$3:$B$7) for each
pair of file names and types from Range2 (A12&B12).
On finding a match, it returns the position (row number) of that value
within Range1.
The INDEX function then returns the value found in the corresponding
position in column C of Range1 ($C$3:$C$7).
¾ Solution:
Use the INDEX and MATCH functions as shown in the following Array
formula:
{=INDEX(A2:A7,MATCH(1,(B2:B7=D2)*(C2:C7<D3)))}
Explanation:
The MATCH function returns the position (row number) of the first pair of
Color & Price values that meet the criteria in cells D2 & D3 (Blue, costs
less than $200).
The INDEX function then returns the Item in column A from the
corresponding position.
¾ Solution:
Use the INDEX and MATCH functions as shown in the following Array
formula:
{=INDEX($C$2:$C$5,MATCH(1,($A$2:$A$5=A9)*($B$2:$B$5=B9),0))}
Explanation:
The MATCH function returns the position (row number) of the first pair of
Item & Color values that meet the criteria in cells A9 & B9 (Sneakers,
Red).
The INDEX function then returns the Price found in the corresponding
position in column C.
¾ Solution:
Use the INDEX and MATCH functions as shown in the following Array
formula:
{=INDEX($C$2:$C$6,MATCH(E2&F2,$A$2:$A$6&$B$2:$B$6,0))}
Explanation:
The MATCH function returns the position (row number) of the first pair of
Category & Item values in columns A & B that meet the criteria in cells
E2 & F2.
The INDEX function returns the value (Price) found in the corresponding
position in column C.
¾ Solution 1:
Use the VLOOKUP function as shown in the following Array formula:
{=VLOOKUP(G2,$A$2:$E$6,{2,3,4,5},FALSE)}
Select range H2:K2 and enter the above Array formula.
Then, copy/paste the formula from cells H2:K2 to H3:K4.
¾ Solution 2:
Use the INDEX and MATCH functions as shown in the following formula
in cell H7:
=INDEX(B$2:B$6,MATCH($G2,$A$2:$A$6,0),1)
Copy the formula and paste it to all cells in the range H7:K9.
Explanation to Solution 1:
The VLOOKUP function searches the first column of range A2:E6 for the
ID entered in G2 and returns the corresponding values from the next four
columns, as follows:
The value in column B (first name) is returned into cell H2.
The value in column C (last name) is returned into cell I2.
The value in column D (gender) is returned into cell J2.
The value in column E (age) is returned into cell K2.
Explanation to Solution 2:
The MATCH function returns the position (row number) within column A
of the ID entered in cell G2.
The INDEX function returns the value found in the corresponding position
in column B (i.e. the First Name matching the ID in cell G2).
On copying the formula to the next cell in the row (from cell H7 to cell
I7)), the INDEX function will update accordingly and return a value from
the next column in the range (i.e. the Last Name from column C).
¾ Solution:
Use the INDEX, MATCH, and MAX functions as shown in the following
Array formula:
{=INDEX(B2:B6,MATCH(MAX(($E$2:$E$6)*($D$2:$D$6="Math")),$E$2:$
E$6,0))}
Copy the formula from cell B8 to cells C8:E8.
Explanation:
The MAX function returns the highest Grade for those IDs that have
"Math" values in column D.
The MATCH function returns the position (row number) of that grade
within column E.
Finally, the INDEX function returns the value stored in the same position
in column B (Student ID).
The column from which the INDEX function returns a value will change
to match the column containing the formula. Thus, on copying the
formula to cell C8, the INDEX function will retrieve the corresponding
year from column C, and so on.
¾ Solution:
Use the ISNA and VLOOKUP functions as shown in the following
formula:
=IF(ISNA(VLOOKUP(B9,A4:B6,2,FALSE)),VLOOKUP(B9,D4:E6,2,FALSE),
VLOOKUP(B9,A4:B6,2,FALSE))
Explanation:
The first VLOOKUP function looks up the first column of range1 (A4:B6)
for the item entered in cell B9, and returns its matching price.
Similarly, the second VLOOKUP function looks up range2 (D4:E6) for the
same item.
If the lookup value is not found in the lookup range, the function returns
the #N/A error.
The ISNA function determines whether or not the value calculated by the
first VLOOKUP function is the #N/A error, and returns TRUE/FALSE
accordingly.
If the result of the ISNA function is TRUE (i.e. the item was not found in
range1), the IF function returns the result of the second VLOOKUP
function. Otherwise (i.e. the item was found in range1), the result of the
first VLOOKUP function is returned.
¾ Solution:
Use the INDEX, MATCH, MIN, IF, and COLUMN functions as shown in
the following Array formula:
{=INDEX(C1:M1,MATCH(MIN(IF(C2:M2<>"
",COLUMN(C2:M2))),COLUMN(C2:M2)))}
Enter the formula in cell B3 and copy/paste it across the row from cell B3
up to cell M3.
Explanation:
The IF function returns an Array containing the column numbers
(calculated by the COLUMN function) of all the non-blank cells in cells
C2:M2.
¾ Solution:
Use the INDEX, MIN, IF, and COLUMN functions as shown in the
following Array formula:
{=INDEX($B$1:$G$1,MIN(IF(B2:G2<>"",COLUMN($B$1:$G$1)-
COLUMN(B1)+1)))}
Explanation:
The IF function returns an Array containing the positions (column
numbers, calculated by the COLUMN functions) of all the non-blank cells
in cells B2:G2
The MIN function returns the smallest value in that Array, which is the
position of the first non-blank cell in row 2.
The INDEX function returns the value stored in the corresponding position
in row 1 (i.e. the column header of the first non-blank cell in row 2).
¾ Solution:
Use the INDEX, SUMPRODUCT, MAX, and COLUMN functions as
shown in the following formula:
=INDEX($A$1:$C$1,
SUMPRODUCT(MAX(($A$2:$C$5=E2)*(COLUMN($A$2:$C$5))))-
COLUMN($A$1)+1)
Explanation:
The following expression returns an Array containing the column number
of each value in cells A2:C5 that matches the look up value (cell E2), and
a "0" (FALSE) for each value that does not.
($A$2:$C$5=E2)*(COLUMN($A$2:$C$5))
The MAX function returns the largest number in that Array (the column
number).
The SUMPRODUCT function returns that column number after having
the column number of the first cell in the range (calculated by the second
COLUMN function) subtracted from it and adding 1.
Thus, the position of that column within range A2:C5 is returned.
Finally, the INDEX function retrieves the value in row 1 that is stored in
the corresponding position (i.e. the column header of the matched value).
¾ Solution:
Use the INDEX, MATCH, and MAX functions as shown in the following
formula:
=INDEX($B$1:$E$1,1,MATCH(MAX(B2:E2),B2:E2,0))
Explanation:
The MAX function returns the highest value from cells B2:E2.
The MATCH function returns the position (column number) of that value
within cells B2:E2.
The INDEX function returns the value stored in the corresponding
position in row 1 (i.e. the header of the highest score in Game1).
Thus, the name of the winner is returned in cell F2.
¾ Solution 1:
Use the OFFSET and MATCH functions as shown in the following
formula:
=OFFSET($A$1,MATCH(B9,$A$1:$A$6,0)-1,MATCH(A9,$A$1:$E$1,0)-1)
¾ Solution 2:
Use the INDEX and MATCH functions as shown in the following Array
formula:
{=INDEX($A$1:$E$6,MATCH(B9,$A$1:$A$6),MATCH(A9,$A$1:$E$1))}
Explanation to Solution1:
The first MATCH function returns the position (row number) within
column A (the index column) of the index value entered in cell B9.
The second MATCH function returns the position (column number)
within row 1 (the index row) of the index value entered in cell A9.
The OFFSET function offsets the reference "A1" by as many rows as the
number calculated by the first MATCH function, minus 1, and as many
columns as the number calculated by the second MATCH function,
minus 1.
Thus, the reference of the cell referred to by the pair of indexes is
returned.
Explanation to Solution 2:
The first MATCH function returns the position (row number) within
column A (the grid’s index column) of the row index value entered in
cell B9.
The second MATCH function returns the position (column number)
within row 1 (the grid’s index row) of the column index value entered in
cell A9.
The INDEX function retrieves the value from cells A1:E6 that is stored at
the intersection of the row and column calculated by the MATCH
functions.
Chapter 5
This chapter deals with formulas that use Logical functions and also those
that are used for the handling of Errors. It includes the following sections:
) Reducing Complexity of IF Functions, Page 216: This section
contains three examples of how to reduce the number of IF functions
used when creating logical formulas.
) Using OR, AND Functions, Page 221: This section contains formulas
that use the OR & AND logical functions to meet multiple criteria.
) Handling Errors, Page 224: This section provides solutions for
avoiding errors such as #VALUE! and #DIV/0! when using formulas.
) Handling Errors with the VLOOKUP Function, Page 234: This section
demonstrates techniques on preventing errors when using the
VLOOKUP function.
Reducing Complexity of IF
Functions
Simplifying Formulas by Reducing the
Complexity of IF Functions (1)
¾ Problem:
The range A2:C8 contains rows of numbers. For each row, we want an
indication of how many of the following conditions are met:
1. Num1 (column A) = 2
2. Num2 (column B) = 4
3. Num3 (column C) = 6
The following formula based on nested IF functions, is very complex:
=IF(A2=2,IF(B2=4,IF(C2=6,"All Conditions","Two
Conditions"),IF(C2=6,"Two Conditions","One Condition")),
IF(B2=4,IF(C2=6, "Two Conditions","One Condition"),IF(C2=6,"One
Condition","None of the Conditions")))
Is there a simpler way to achieve the same results?
¾ Solution:
Use the CHOOSE function as shown in the following formula:
=CHOOSE((A2=2)+(B2=4)+(C2=6)+1,"None of the Conditions","One
Condition","Two Conditions","All Conditions")
Explanation:
The CHOOSE function returns the nth item in a list of values.
The first argument of the function is N, while the rest of the arguments are
a list of values comprising the results to be returned.
N, in this case, is the result of the following calculation:
Each of the following three expressions returns "1" (TRUE) if the value
stored in the specified cell equals the indicated number, and "0" (FALSE) if
it doesn’t:
A2=2
B2=4
C2=6
The results of the three expressions are added together (creating a count
of the met conditions) and 1 is added to the total.
Depending on the value of N (1 to 4), the CHOOSE function returns the
nth member of the list of strings making up the return arguments.
Thus, in this case, the CHOOSE function returns an appropriate string
indicating how many conditions have been met by each row.
¾ Solution:
Use the IF and OR functions as shown in the following Array formula:
{=IF(OR(B2=$A$2:$A$4),"Primary Color","Not a Primary Color")}
Explanation:
The following expression returns an Array consisting of TRUE for every
value in cells A2:A4 that equals the value stored in cell B2 and FALSE for
every other value:
B2=$A$2:$A$4
The OR function returns TRUE if any of the results in that Array are TRUE.
Otherwise, it returns FALSE.
Thus, it returns TRUE if the color in cell B2 appears in the Primary Colors
list (cells A2:A4) and FALSE if it doesn’t.
If TRUE is returned, the IF function returns the string "Primary Color".
Otherwise, it returns "Not a Primary Color".
Hence, the Array formula allows us to compare one value with a range of
other values, without having to specify each individual comparison, as
was the case in the original formula.
¾ Solution 1:
Use the following formula:
=($A$2>D1)+($A$3>D1)+($A$4>D1)>0
¾ Solution 2:
Use the OR function as shown in the following Array formula:
{=OR($A$2:$A$4>D1)}
Explanation to Solution 1:
Each of the following three expressions returns "1" (TRUE) if the value
stored in the specified cell is greater than the value in cell D1, and "0"
(FALSE) if it isn’t:
$A$2>D1
$A$3>D1
$A$4>D1
If the sum of all three expressions is greater than 0, TRUE is returned.
Otherwise, FALSE is returned.
Thus, TRUE will be returned if there is at least one number in List1 greater
than the number in cell D1.
Explanation to Solution 2:
The following expression returns an Array consisting of TRUE for every
value in cells A2:A4 that is greater than the value stored in cell D1 and
FALSE for every value that isn’t:
$A$2:$A$4>D1
The OR function returns TRUE if any of the results in that Array are TRUE.
Otherwise, it returns FALSE.
Thus, TRUE will be returned if there is at least one number in List1 greater
than the number in cell D1.
¾ Solution:
Use the IF, AND, and OR functions as shown in the following formula:
=IF(AND(A2=10,OR(B2=5,C2=2)),1,0)
Explanation:
The OR function returns TRUE if either cell B2 equals 5 or cell C2 equals
2. Otherwise, it returns FALSE.
The AND function returns TRUE if both cell A2 equals 10 and the result
of the OR function is TRUE.
If TRUE is returned by the AND function, the IF function returns "1".
Otherwise, it returns "0".
¾ Solution:
Use the AND, MOD, and OR functions as shown in the following
formula:
=AND(MOD(A2,2)=0,OR(A2<3,A2>8))
Explanation:
The MOD function divides the number in cell A2 by 2 and returns the
remainder. Even numbers will have a remainder of 0.
The OR function returns TRUE if the number in cell A2 is either smaller
than 3 or greater than 8.
The AND function returns TRUE only if the MOD function equals 0 and
the OR function is TRUE. Otherwise, FALSE is returned.
¾ Solution:
Use AND and COUNTIF functions in the following Array formula:
{=AND(COUNTIF(A2:C6,E2:E10))}
Explanation:
The COUNTIF function returns an Array consisting of the number of
times each value in column E (cells E2:E10) appears in the range A2:C6.
A count of 0 represents a number in column E that does not appear in
cells A2:C6, and any other count represents a number that does.
The AND function returns TRUE if all the numbers (counts) in the Array
are not equal to 0 (0 represents a FALSE argument in logical functions).
Otherwise (if there is at least one 0 in the Array), it returns FALSE.
Thus, the formula returns TRUE if each of the numbers in column E
appears at least once in range A2:C6, and FALSE if any of them are
missing.
Handling Errors
Ignoring Blank Cells when Performing
Calculations
¾ Problem:
Columns A & B contain numbers as well as empty cells.
We want to be able to multiply each number in column A with the
matching number in Column B without getting false results or errors.
¾ Solution:
Use IF, AND, and ISNUMBER functions in the following formula:
=IF(AND(ISNUMBER(A2), ISNUMBER(B2)),A2*B2,"")
Explanation:
The first ISNUMBER function determines whether or not the value stored
in cell A2 is a number and returns TRUE/FALSE accordingly.
The second ISNUMBER function determines whether or not the value
stored in cell B2 is a number and returns TRUE/FALSE accordingly.
The AND function returns TRUE only if both ISNUMBER functions
returned TRUE (both cell A2 and cell B2 contain numbers).
Otherwise, it returns FALSE.
If TRUE is returned by the AND function, the IF function multiplies cell
A2 by cell B2 and returns the result. Otherwise, it returns a blank cell (" ").
Thus, if one or both of the cells in columns A & B are blank, the formula
returns a blank cell, rather than an error or 0.
¾ Solution:
Use the IF and SUM functions as shown in the following formula:
=IF(A5>0,SUM(B5:C5)-A5)
Explanation:
The SUM function adds all the values in range B5:C5, disregarding any
cells that contain blanks.
Thus, the blank in cell B5 does not cause any errors.
The IF function determines whether or not the value in cell A5 is greater
than 0.
If so, the IF function returns the result of the SUM function after
subtracting the value stored in cell A5.
Otherwise, it returns FALSE.
¾ Solution:
Use the IF function as shown in the following formula:
=IF(B2=0,"",A2/B2)
Explanation:
The IF function determines whether or not cell B2 equals zero (i.e. the
value stored in B2 = 0 or the cell is empty).
If so, the IF function returns a blank value (" "). Otherwise, cell A2 is
divided by cell B2 and the result returned.
Thus, the display of #DIV0! errors for invalid values is prevented.
¾ Solution:
Use AVERAGE, IF, and ISERROR functions in the following Array
formula:
{=AVERAGE(IF(ISERROR(C2:C7),"",C2:C7))}
Explanation:
The ISERROR function returns an Array containing TRUE for each value
in column C (C2:C7) that is an error and FALSE for each value that isn’t.
For each TRUE in the ISERROR Array, the IF function returns a blank (" ").
For each FALSE, it returns the corresponding number from column C.
Thus, it returns an Array containing all the valid values in column C and
blanks for all the non-valid values.
The AVERAGE function returns the average of all the values in that Array,
disregarding the blanks.
Hence, it ignores the cells containing #DIV0! errors when averaging the
results in column C.
¾ Solution:
Use the IF and AND functions as shown in the following formula:
=IF(AND(A2=5,B2=8),TRUE,FALSE)
Explanation:
The "&" symbol cannot be used in Excel to express a combination of
conditions.
To express such a combination, use the AND function.
The AND function returns TRUE only if both cell A2 equals 5 and cell B2
equals 8.
If TRUE is returned, the IF function returns the text TRUE, otherwise, it
returns the text FALSE.
¾ Solution:
Use the AVERAGE, IF, and ISNUMBER functions as shown in the
following Array formula:
{=AVERAGE(IF(ISNUMBER(A1:A5)*ISNUMBER(B1:B5),A1:A5-B1:B5))}
Explanation:
In order to express a combination of multiple conditions in an Array
formula, use the "*" operator rather than the AND function.
The two ISNUMBER functions in the formula determine whether or not
each cell in column A and column B contains a numeric value and return
TRUE/FALSE accordingly.
The IF function returns an Array containing the difference between each
pair of cells in columns A & B, for which TRUE was returned by both
ISNUMBER functions (i.e. the cells in column A and column B both
contain numeric values).
The AVERAGE function returns the average of the numbers in that Array.
Thus, the formula returns the average difference between each pair of
values in columns A & B (providing both cells are not empty).
¾ Solution:
Use the SUMPRODUCT, MONTH, ISBLANK, and ISNUMBER functions
as shown in the following formula:
=SUMPRODUCT((MONTH(A2:A9)=1)*(ISBLANK(B2:B9))*(ISNUMBER(A
2:A9)))
Explanation:
The incorrect result occurs because Excel considers empty date cells to be
January 1900 dates.
Thus, each empty cell in column A was included in the count of January
dates.
To avoid that error and ignore empty cells, the ISNUMBER function was
added to the formula.
The MONTH function returns the month number of each date in column A.
If that number equals "1" (January), TRUE is returned; all other months
return FALSE.
The ISBLANK function determines whether or not each value in column B
is blank, and returns TRUE/FALSE accordingly.
The ISNUMBER function determines whether or not each value in
column A is numeric, and returns TRUE/FALSE accordingly.
Finally, the SUMPRODUCT function returns the count of all the rows in
range A2:B9 for which all three expressions returned TRUE.
Thus, a count is returned of all the days in January for which 0 hours were
worked.
¾ Solution:
Use the MOD function as shown in the following formula:
=MOD(B2-A2,1)
Note:
Apply hh:mm format to all cells containing the formula.
Explanation:
As time values are stored in Excel as fractions of 24 (1 hour=1/24), the
result of B2-A2 is a positive or negative fraction.
The MOD function divides that fraction by 1 (representing 24 hours) and
returns the remainder.
¾ Solution:
Use the IF, ISERROR, and VLOOKUP functions as shown in the following
formula:
=IF(ISERROR(VLOOKUP(B2,$A$2:$A$9,1,FALSE)),"Number Not
Found",VLOOKUP(B2,$A$2:$A$9,1,FALSE))
Explanation:
The VLOOKUP function looks up column A for the number stored in B2
and returns that value if a match is found. If the value is not found, the
function returns the #N/A error.
The ISERROR function determines whether or not the result of the
VLOOKUP function was an error (i.e. whether or not the search was
successful), and returns TRUE/FALSE accordingly.
If TRUE, the IF function returns the string "Number Not Found".
Otherwise, it returns the result of the VLOOKUP function.
Thus, if there is no exact match, the formula returns the text "Number Not
Found", rather than an error.
¾ Solutions:
There are several possible solutions:
Use the TRIM function to remove any redundant spaces from the
values in List1: =TRIM(A2)
Use the ROUND function to round the numbers in List1 to the nearest
integer: =ROUND(A3,0)
Use the VALUE function to convert text-formatted numbers to actual
numbers : =VALUE(A4)
Explanation:
The most likely cause of error is that the values from both lists are not
100% identical.
They may have invisible differences such as different formatting,
redundant spaces, etc.
In this case:
) The text in cell A2 has a redundant space at the beginning. Therefore
it does not match the text in cell B4.
Using the TRIM function will remove the space and enable the
VLOOKUP function to find a match.
¾ Solution:
Use the IF, ISNA, and VLOOKUP functions as shown in the following
formula:
=IF(ISNA(VLOOKUP(B2,$A$2:$A$7,1,FALSE)),B2&"Not
Found",VLOOKUP(B2,$A$2:$A$7,1,FALSE)&"Found")
Explanation:
The VLOOKUP function searches List1 for the value stored in cell B2 and
returns it if there is a match.
If that color is not found, the VLOOKUP function returns the #N/A error.
The ISNA function determines whether or not the result of the VLOOKUP
function is the #N/A error and returns TRUE/FALSE accordingly.
If TRUE, the IF function returns a string composed of the look up value
(the color) and the text "Not Found".
Otherwise, it returns a string composed of the result of the VLOOKUP
function (the matched color) and the text "Found".
Thus, in all cases, a string is returned that includes the lookup term as
well as an indication of whether or not the value was found.
¾ Solution:
Use the IF, ISNA, and VLOOKUP functions as shown in the following
formula:
=IF(ISNA(VLOOKUP(A3,$A$9:$B$14,1,FALSE)),"Not
Found",VLOOKUP(A3,$A$9:$B$14,2,FALSE))
Explanation:
The VLOOKUP function searches the first column of Range2 for the
number stored in cell A3 (Range1). If successful, the corresponding value
from the second column is returned.
If a match is not found, the VLOOKUP function returns the #N/A error.
The ISNA function determines whether or not the result of the VLOOKUP
function is the #N/A error, and returns TRUE/FALSE accordingly.
If TRUE is returned, the IF function returns the string "Not Found".
Otherwise, it returns the result of the VLOOKUP function (i.e. the text
matching the look up value).
Chapter 6
Counting
¾ Solution:
Use the COUNT, COUNTA, COUNTBLANK, and COUNTIF functions as
shown in the following formulas:
1. =COUNT(A2:A13)
2. =COUNTA(A2:A13)
3. =COUNTBLANK(A2:A13)
4. =COUNTIF(A2:A13,">5")
5. =COUNTIF(A2:A13,"*")
6. =COUNTIF(A2:A13,"*Excel*")
7. =COUNTIF(A2:A13,"???")
¾ Solution1:
To count the number of unique values use the SUM, IF, and FREQUENCY
functions as shown in the following formula:
= SUM(IF(FREQUENCY(A2:A13,A2:A13)>0,1))
¾ Solution 2:
To count the number of unique data use the SUMPRODUCT and
COUNTIF functions as shown the following formula:
=SUMPRODUCT((A2:A13<>"")/COUNTIF(A2:A13,A2:A13&""))
Explanation:
) Explanation to Solution 1:
The FREQUENCY function returns an Array consisting of the
frequency within the list of each numeric value in List1 (cells
A2:A13).
For the first occurrence of a specific value, the function returns the
number of occurrences of that value. For each occurrence of that
same value after the first, the function returns a zero. Thus, each "0" in
the FREQUENCY Array represents a duplicate of a value that has
already been processed.
The IF function returns an Array consisting of "1" for each value in the
FREQUENCY Array that is greater than 0, and "0" for each value that
isn’t.
The SUM function adds all the numbers in the Array returned by the
IF function.
The result represents the number of unique numeric values in List1.
) Explanation to Solution 2:
The COUNTIF function returns an Array containing the number of
times each value (of any type) in List1 (cells A2:A13) appears within a
modified version of List1 which has had a blank (" ") added to the end
of each value.
The blank is added in order to convert any empty cells in List1 to
blanks and, thus, avoid errors in the formula.
The following expression returns an Array consisting of "1" (TRUE) for
every non-blank cell in List1 and "0" (FALSE) for every blank one:
A2:A13<>""
Each value in that Array, representing a value in List1, is then divided
by the corresponding value (count) from the COUNTIF Array, and a
new Array, containing the results, is returned.
The SUM function adds the numbers in that Array.
The result represents the number of unique values (of any type) in
List1.
¾ Solution:
Use the COUNTIF and AVERAGE functions as shown in the following
formulas:
To count values below average:
=COUNTIF(A2:A9,"<"&AVERAGE(A2:A9))
To count values above average:
=COUNTIF(A2:A9,">"&AVERAGE(A2:A9))
Explanation:
) Formula for Values below Average:
The AVERAGE function returns the average of all the values in List1
(cells A2:A9).
The COUNTIF function returns the number of values in List1 that are
smaller than the number returned by the AVERAGE function.
) Formula for Values above Average:
The AVERAGE function returns the average of all the values in List1
(cells A2:A9).
The COUNTIF function returns the number of values in List1 that are
greater than the number returned by the AVERAGE function.
¾ Solution:
Use the SUM, IF, and COUNTIF functions as shown in the following
Array formula:
{=SUM(IF(COUNTIF(A2:A7,A2:A7&"")=1,1,0))}
Explanation:
The COUNTIF function returns an Array containing the number of times
each value in List1 (cells A2:A7) appears within a modified version of
List1 which has had a blank (" ") added to the end of each value.
The blank is added in order to convert any empty cells in List1 to blanks
and, thus, avoid errors in the formula.
The IF function returns an Array consisting of "1" for each count in the
COUNTIF Array that equals 1 (representing a value in List1 that appears
only once within the list) and "0" for each count that doesn’t.
The SUM function adds the values in the Array returned by the IF
function.
The result represents the number of values in List1 that appear only once
within the list.
¾ Solution:
Use the SUMPRODUCT, LEN, and SUBSTITUTE functions as shown in
the following formula:
=SUMPRODUCT(LEN($A$2:$A$6)- LEN(SUBSTITUTE($A$2:$A$6,B2,"
")))/LEN(B2)
Explanation:
The SUBSTITUTE function returns an Array consisting of all the strings in
column A after they have been modified by having each occurrence of
the substring stored in cell B2 replaced by nothing.
The LEN function creates an Array containing the lengths of all the strings
in the Array returned by the SUBSTITUTE function.
That Array is subtracted from another Array which contains the lengths of
all the original strings in column A.
Thus, an Array is created that contains the difference in length between
each original string in column A and the one returned by the
SUBSTITUTE function.
Each item in that Array is then divided by the length of the substring in
cell B2 (calculated by the LEN function).
Finally, the SUMPRODUCT function adds the results of that calculation,
which returns the total number of times the substring in cell B2 appears
within any of the strings in column A.
¾ Solution:
Use the SUM, IF, and ISTEXT functions as shown in the following Array
formula:
{=SUM(IF(ISTEXT(A1:B5),1,0))}
Explanation:
The ISTEXT function returns an Array consisting of TRUE for every cell in
range A1:B5 that contains a text value and FALSE for every cell that
doesn’t.
The IF function returns an Array consisting of "1" for each TRUE value in
the ISTEXT Array and "0" for every FALSE value in that Array.
The SUM function adds all the values in the Array returned by the IF
function.
The result represents the number of cells containing text values in range
A1:B5.
¾ Solution 1:
Use the COUNTA and COUNT functions as shown in the following
formula:
=COUNTA(A1:C5)-COUNT(A1:C5)
¾ Solution 2:
Use the COUNTIF function as shown in the following formula:
=COUNTIF(A1:C5,"*")
Explanation:
) COUNTA & COUNT functions:
The COUNTA function returns the number of values (non-empty
cells) within range A1:C5.
The COUNT function returns the number of numeric values within
that range.
The number of numeric values in range A1:C5 (returned by the
COUNT function) is then subtracted from the total number of values
in that range (returned by the COUNTA function).
The result represents the number of cells within range A1:C5 that
contain text.
) COUNTIF function:
The COUNTIF function returns the number of values in range A1:C5
that are identical to the "*" symbol.
The "*" symbol is used as a text wildcard in Excel, meaning that it
represents any text value.
Thus, the count returned by the COUNTIF function includes all text
cells within range A1:C5.
¾ Solution:
Define three Names:
Insert → Name → Define, or press <Ctrl+F3>
Name: FirstName, Refers to: $B$1
Name: Rng, Refers to: $B$1:$B$100
Name: DynamicRange, Refers to the following OFFSET formula:
=OFFSET(FirstName,0,0,COUNTA(Rng))
Use the SUM, LEFT, and OFFSET functions as shown in the following
Array formula, which will count the number of combined first and last
names matching the above criteria in "DynamicRange":
{=SUM((DynamicRange<>"")*(LEFT(DynamicRange)=LEFT(OFFSET(D
ynamicRange,0,1))))}
Explanation:
) Formula defining DynamicRange:
The COUNTA function returns the number of values (non-empty
cells) in Rng (defined name for range B1:B100).
The OFFSET function returns a reference that starts at FirstName
(defined name for cell B1) and spreads over as many rows in column
B as the number calculated by the COUNTA function.
Thus, the OFFSET function returns the reference of the current range
of first names (column B).
As the result of the COUNTA function changes upon the removal/
addition of names to the range, the reference returned by the OFFSET
function updates accordingly to exclude/include only those cells
within the range.
) Array Formula in Cell D2:
The following expression returns an Array consisting of "1" (TRUE) for
every non-blank cell in DynamicRange (defined name for the range
returned by the first formula) and "0" (FALSE) for every blank one:
DynamicRange<>""
The first LEFT function returns the leftmost character of each cell in
DynamicRange (i.e. it returns the first letter of each first name
currently listed in column B).
The OFFSET function offsets DynamicRange 1 column to the right.
Thus, it returns the reference of the current range of last names
(column C).
The second LEFT function returns the leftmost character of each cell
in the range returned by the OFFSET function (i.e. the first letter of
each last name currently listed in column C).
The first letter of each first name is then compared with the first letter
of the corresponding last name. That comparison yields an Array
consisting of "1" (TRUE) for each identical pair and "0" (FALSE) for
each different pair.
¾ Solution:
Use the LEN and SUBSTITUTE functions as shown in the following
formula:
=(LEN(A2)-LEN(SUBSTITUTE(A2,B2,"")))/LEN(B2)
Explanation:
The SUBSTITUTE function returns the string in cell A2 after it has been
modified by having each occurrence of the substring stored in cell B2
replaced by a blank (" ").
The LEN function (the second one in the formula) returns the length of
that string.
That length is then subtracted from the length of the original string in cell
A2, calculated by the first LEN function.
The result is then divided by the length of the substring in cell B2
(calculated by the third LEN function).
The result of that calculation represents the number of times the substring
in cell B2 appears within the corresponding string in cell A2.
¾ Solution:
Use the SUMPRODUCT, SUBSTITUTE, and VALUE functions as shown
in the following formula:
=SUMPRODUCT(--(VALUE((SUBSTITUTE($A$2:$A$7,"T","")))<VALUE
(SUBSTITUTE(B2,"T",""))))
Explanation:
The first SUBSTITUTE function returns an Array consisting of each string
in List1qual (cells A2:A7) which has had the "T" removed (replaced with a
blank).
The first VALUE function converts each string in that Array to a numeric
value.
Thus, it returns an Array consisting of the numbers included within each
string in List1.
Similarly, the second VALUE and SUBSTITUTE functions return the
number included within the string stored in cell B2 (criteria).
Each number in the Array created above is compared with the criteria
number, creating an Array that consists of TRUE for each number that is
smaller than the criteria and FALSE for each number that isn’t.
The "--" symbol converts each TRUE/FALSE value in that Array to "1"/"0"
accordingly, and the SUMPRODUCT function adds all the values in the
Array.
The result represents the number of strings in List1 which contain a
number smaller than the one within the string stored in cell B2.
¾ Solution:
Use the COUNTIF and DATE functions as shown in the following
formula:
=COUNTIF(A2:A10,">="&DATE(2005,1,1))
Explanation:
The DATE function returns the date value that corresponds with the year,
month, and day specified in the formula (2005, 1, and 1), i.e. 01/01/2005.
The COUNTIF function returns the number of dates in column A (cells
A2:A10) that are later than or equal to that date.
¾ Solution 1:
Use the SUMPRODUCT and MONTH functions as shown in the
following formula:
=SUMPRODUCT(--(MONTH(A2:A6)=B2))
¾ Solution 2:
Use the SUM, IF, and MONTH functions as shown in the following Array
formula:
{=SUM(IF(MONTH(A2:A6)=B2,1))}
Explanation:
The reason for the above error is that an array of values (MONTH(A2:A6))
was entered as the first argument of the COUNTIF function.
The first argument of the COUNTIF function (and SUMIF function as
well) must be a range reference.
) SUMPRODUCT Formula (cell C2):
The MONTH function returns an Array consisting of the month
number (1-12) that corresponds with each date in column A (cells
A2:A6).
Each month number in that Array is compared with the month criteria
in cell B2, creating an Array that consists of TRUE for every month
number that equals the criteria and FALSE for every month number
that doesn’t.
The "--" sign converts every TRUE/FALSE in that Array to 1/0
accordingly.
The SUMPRODUCT function adds all the values in the Array, and,
thus, returns the number of dates in column A that match the month
criteria in cell B2.
) Array Formula (cell D2):
The MONTH function returns an Array consisting of the month
number (1-12) that corresponds with each date in column A (cells
A2:A6).
Each month number in that Array is compared with the month criteria
in cell B2, creating an Array that consists of TRUE for every month
number that equals the criteria and FALSE for every month number
that doesn’t.
The IF function returns an Array that consists of "1" for each TRUE
value in the above Array.
Finally, the SUM function adds all the values in the Array returned by
the IF function, and, thus, returns the number of dates in column A
that match the month criteria in cell B2.
¾ Solution:
Use the COUNTIF function as shown in the following formula:
=COUNTIF($A$2:$A$7,">"&B2)-COUNTIF($A$2:$A$7,">"&B3)
Explanation:
The first COUNTIF function returns the number of time values in List1
(cells A2:A7) that are greater than the time value in cell B2.
The second COUNTIF function returns the number of time values in List1
that are greater than the time value in cell B3.
The number (count) returned by the second COUNTIF function is then
subtracted from the number returned by the first one.
The result of that calculation represents the number of time values in List1
that occur between the pair of hours listed in cells B2:B3.
¾ Solution:
Use the SUMPRODUCT, MOD, and COLUMN functions as shown in the
following formula:
=SUMPRODUCT(--(MOD(COLUMN($A$1:$J$1)-
COLUMN($A$1)+1,3)=0)*($A$1:$J$1>$A$4))
Explanation:
The COLUMN functions in the following expression return the column
numbers of each value in row 1 (cells A1:J1) and of the first value in the
row (cell A1): (MOD(COLUMN($A$1:$J$1)-COLUMN($A$1)+1,3)=0)
Those column numbers are then used to calculate serial numbers
matching each value in row 1.
The MOD function divides each of those serial numbers by 3 and returns
the remainder.
The result of the expression is an Array consisting of "1" (TRUE) for every
value in row 1 where the serial number is divisible by 3 (the remainder
calculated by the MOD function is 0) and "0" (FALSE) for all other values.
The following expression returns an additional Array consisting of "1"
(TRUE) for every value in row 1 that is greater than the criteria in cell A4
and "0" (FALSE) for every value that isn’t:
$A$1:$J$1>$A$4
The SUMPRODUCT function adds the products of the corresponding
items in the Arrays returned by the above expressions.
The result represents the number of values in row 1 that are greater than
the criteria specified in cell A4 and also members of the set of every 3rd
value in the range.
¾ Solution:
Use the SUMPRODUCT and MOD functions as shown in the following
formula:
=SUMPRODUCT((MOD(A2:A7,2)=0)*(MOD(B2:B7,2)=0))
Explanation:
The first MOD function divides each number in column A (cells A2:A7)
by 2 and returns an Array consisting of the remainder of each them.
The following expression returns an Array consisting of "1" for each
remainder in the MOD Array that equals 0 and "0" for each remainder
that doesn’t: (MOD(A2:A7,2)=0)
Hence, the Array consists of "1" for every even number in column A and
"0" for every odd one.
A similar expression is used to evaluate column B.
¾ Solution:
Use the SUM, COUNTIF, and INDIRECT functions as shown in the
following formula:
=SUM(COUNTIF(INDIRECT("Sheet"&{1,2,3}&"!A1:B3"),">"&A2))
Explanation:
The text "Sheet" is joined with each of the numbers 1, 2, & 3, and the text
"!A1:B3".
The result is an Array consisting of three strings that represent the
reference of range A1:B3 in Sheets 1, 2, & 3.
¾ Solution:
Use the SUMPRODUCT function as shown in the following formula:
=SUMPRODUCT((B2:B7=F1)*(C2:C7=F2))
Explanation:
The following expression returns an Array consisting of "1" (TRUE) for
each value in column B (cells B2:B7) that matches the gender criteria in
F1 and "0" (FALSE) for each value that doesn’t:
B2:B7=F1
Similarly, the following expression returns an Array consisting of "1"
(TRUE) for each value in column C (cells C2:C7) that equals the age
criteria in cell F2 and "0" (FALSE) for each value that doesn’t:
C2:C7=F2
The SUMPRODUCT function adds the products of the corresponding
items in the two Arrays created above.
The result represents the number of rows in range A2:C7 that match the
criteria stored in cells F1 & F2.
¾ Solution:
To count the numbers in List1 that are, for example, between 1 and 2
(B2:B3), use the COUNTIF function as shown in the following formula:
=COUNTIF($A$2:$A$10,">="&B2)-COUNTIF($A$2:$A$10,">"&B3)
Explanation:
The first COUNTIF function returns the number of values in List1 (cells
A2:A10) that are greater than or equal to the value stored in cell B2.
The second COUNTIF function returns the number of values in List1 that
are greater than the value stored in cell B3.
The number returned by the second COUNTIF function is then subtracted
from the number returned by the first one.
The result of that calculation represents the number of values in List1 that
are between the values in cells B2 & B3.
¾ Solution 1:
Use the COUNTIF function as shown in the following formula:
=COUNTIF(A2:A7,">20")-COUNTIF(A2:A7,">=50")
¾ Solution 2:
Use the SUMPRODUCT function as shown in the following formula:
=SUMPRODUCT((A2:A7>20)*(A2:A7<50))
Explanation:
) COUNTIF Formula:
The first COUNTIF function returns the number values in List1 (cells
A2:A7) that are greater than 20.
The second COUNTIF function returns the number of values in List1
that are greater than or equal to 50.
The number returned by the second COUNTIF function is then
subtracted from the number returned by the first one.
The result of that calculation represents the number of values in List1
that are greater than 20 and smaller than 50.
) SUMPRODUCT Formula:
The following expression returns an Array consisting of "1" (TRUE) for
each value in List1 (cells A2:A7) that is greater than 20 and "0"
(FALSE) for each value that isn’t:
A2:A7>20
Similarly, the following expression returns an Array consisting of "1"
(TRUE) for each value in List1 that is smaller than 50 and "0" (FALSE)
for each value that isn’t:
A2:A7<50
The SUMPRODUCT function adds the products of the corresponding
items in the two Arrays created above.
The result represents the number of values in List1 that are greater
than 20 and smaller than 50.
¾ Solution:
Use the SUM, MMULT, IF, and TRANSPOSE functions as shown in the
following Array formula:
{=SUM(($A$2:$A$13=D2)/(($A$2:$A$13<>D2)+MMULT(--
(IF($A$2:$A$13=D2,$B$2:$B$13)=TRANSPOSE($B$2:$B$13)),--
($A$2:$A$13=D2))))}
Explanation:
The MMULT function, using the IF and TRANSPOSE functions, returns an
Array consisting of the number of times each item in column B (cells
B2:B13) appears next to the salesperson specified in cell D2.
The following expression returns an Array consisting of "1" (TRUE) for
each ID in column A that is different than the one stored in cell D2 and
"0" (FALSE) for each ID that isn’t:
$A$2:$A$13<>D2
The corresponding values in the two above Arrays are added, and the
results are returned in a single Array.
Thus, an Array is created that consists of the total number of times each
ID & Item combination appears in columns A & B.
The following expression returns an additional Array consisting of "1"
(TRUE) for each ID in column A that is the same as the one stored in cell
D2 and "0" (FALSE) for each ID that isn’t:
$A$2:$A$13=D2
Each value in that Array is then divided by the corresponding value in the
Array calculated above and the SUM function adds the results.
Thus, the formula returns the number of unique items sold by the
salesperson listed in cell D2.
¾ Solution:
Use the SUMPRODUCT function as shown in the following formula:
=SUMPRODUCT((B2:B17=F2)*(C2:C17>F3))
Explanation:
The following expression returns an Array consisting of "1" (TRUE) for
each quarter number in column B (cells B2:B17) that equals the quarter
criteria in cell F2 (1) and "0" (FALSE) for each quarter number that doesn’t:
B2:B17=F2
Similarly, the following expression returns an Array consisting of "1"
(TRUE) for each score in column C (cells C2:C17) that is higher than the
score criteria in F3 (3) and "0" (FALSE) for each score that isn’t:
C2:C17>F3
The SUMPRODUCT function adds the products of the corresponding
items in the two Arrays created above.
The result represents the number of players in column A who scores over
3 points (cell F3) in the first quarter (cell F2).
¾ Solution:
Use the SUMPRODUCT function as shown in the following formula:
=SUMPRODUCT((B2:B5<>"")*(C2:C5="A"))
Explanation:
The following expression returns an Array consisting of "1" (TRUE) for
each non-blank cell in cells B2:B5 (an answered question) and "0"
(FALSE) for each blank cell (an unanswered question):
B2:B5<>""
Similarly, the following expression returns an Array consisting of "1"
(TRUE) for each answer in cells C2:C5 that equals "A" and "0" (FALSE) for
each answer that doesn’t:
C2:C5="A"
The SUMPRODUCT function adds the products of the corresponding
items in the two Arrays created above.
The result represents the number of students who answered both
questions and answered "A" to the second question (column C).
¾ Solution:
Use the SUMPRODUCT, MONTH, and RIGHT functions as shown in the
following formula:
=SUMPRODUCT((MONTH(B2:B6)=C2)*(RIGHT(A2:A6,3)=C3))
Explanation:
The MONTH function returns an Array consisting of the month number
(1-12) that corresponds with each creation date in column B (cells B2:B6).
Each month number in that Array is compared with the month criteria in
cell C2 (April), creating an Array that consists of "1" (TRUE) for every
month number that equals the criteria and "0" (FALSE) for every month
number that doesn’t.
The RIGHT function returns an Array consisting of the three rightmost
characters (the file type) of each string in column A (cells A2:A6).
Each string in that Array is compared with the string in C3 ("xls"), and the
result is an Array consisting of "1" (TRUE) for every string that matches the
criteria and "0" (FALSE) for every string that doesn’t.
The SUMPRODUCT function adds the products of the corresponding
items in the two Arrays created above.
The result is the number of Excel files (ending in "xls") in the range A2:B6
that were created in April (cell C2).
¾ Solution:
Use the SUMPRODUCT, INT, and MOD functions as shown in the
following formula:
=SUMPRODUCT((INT(A2:A6)=B2)*(MOD(A2:A6,1)>C2))
Explanation:
The INT function rounds down each date and time value in column A
(cells A2:A6) to the nearest integer.
Thus, it returns an Array consisting of the date part only of each value in
column A.
Each date value in that Array is compared with the criteria date in cell B2,
and the result is an Array that consists of "1" (TRUE) for every date that
matches the criteria and "0" (FALSE) for every date that doesn’t.
The MOD function divides each date and time value in column A by 1
and returns the remainder.
Thus, it returns an Array consisting of the time part only of each value in
column A.
Each time value in that Array is compared with the time value in cell C2,
and the result is an Array that consists of "1" (TRUE) for every time value
that is greater than the criteria in cell C2 and "0" (FALSE) for every time
that isn’t.
The SUMPRODUCT function adds the products of the corresponding
values in the two Arrays created above.
The result is the number of date and time entries in column A with
matching date criteria (cell B2) and a time value greater than the one
specified in cell C2.
¾ Solution:
To find the number of items sold between 20:00 and 20:30 use the
SUMPRODUCT function as shown in the following formula:
=SUMPRODUCT(($B$2:$B$5<C3)*($B$2:$B$5>=C2))
Explanation:
The following expression returns an Array consisting of "1" (TRUE) for
each time value in column B (cells B2:B5) that is earlier than the time
value stored in cell C3 (20:30) and "0" (FALSE) for each time value that
isn’t:
$B$2:$B$5<C3
Similarly, the following expression returns an Array consisting of "1"
(TRUE) for each time value in column B that is later than or equal to the
time value stored in cell C2 (20:00) and "0" (FALSE) for each time value
that isn’t:
$B$2:$B$5>=C2
The SUMPRODUCT function adds the products of the corresponding
items in the two Arrays created above.
The result is the number of time values in column B that are later than
20:00 and earlier than 20:30, which is equivalent to the number of items
sold in that 30 minute time period.
¾ Solution:
Use the SUM and COUNTIF functions as shown in the following Array
formula:
{=SUM(COUNTIF(B2:B9,A2:A4))}
Explanation:
The COUNTIF function returns an Array consisting of the number of
times each value in List1 (cells A2:A4) appears within List2 (cells B2:B9).
The SUM function adds the values in that Array.
Thus, it returns the total number of times any of the numbers in List1
appear within List2.
¾ Solution:
Use the COUNTIF and ROW functions as shown in the following formula
in the first cell (B2) of the new list, and copy the formula down the
column:
=COUNTIF($A$2:$A$6,"<"&ROW()-ROW($B$2)+1)
Explanation:
The ROW functions in the following expression return the row numbers
of the current cell and of the first cell in the result column (cell B2):
ROW()-ROW($B$2)+1
Based on those row numbers, the expression calculates the criteria
according to which we would like to count.
Thus, it calculates "1" in the first cell of the result column (row 2), "2" in
the second cell (row 3), and so on.
The COUNTIF function returns the number of values in List1 (cells
A2:A6) that are smaller than the calculated criteria.
Thus, when copied down column B, the formula creates a new list where
the first value is the number of values in List1 that are smaller than 1, the
second value is the number of values in List1 smaller than 2, and so on.
¾ Solution:
Use the SUMPRODUCT, SUBTOTAL, OFFSET, ROW, and MIN functions
as shown in the following formula:
=SUMPRODUCT(($B$2:$B$22=A26)*(SUBTOTAL(3,OFFSET($B$2,ROW
($B$2:$B$22)-MIN(ROW($B$2:$B$22)),,))))
Enter the above formula next to the 4 possible answers (cells B26:B29).
Explanation:
The first ROW function in the following expression returns an Array
consisting of the row number of each cell in column B (cells B2:B22):
ROW($B$2:$B$22)-MIN(ROW($B$2:$B$22))
The row number of the first cell in the range (cell B2), calculated by the
MIN function and the second ROW function, is subtracted from each row
number in that Array.
The OFFSET function offsets the reference of cell B2 by as many rows as
each number in the above Array.
Thus, the OFFSET function returns an Array consisting of the reference of
each cell in column B.
The SUBTOTAL function returns an Array consisting of the number of
values in each cell reference in the OFFSET Array.
As the SUBTOTAL function ignores hidden cells, the Array consists of "0"
for every cell in column B that is currently hidden and "1" for every cell
that is currently displayed.
The following expression returns an Array consisting of "1" (TRUE) for
each answer in column B (hidden or not) that matches the answer criteria
in cell A26 and "0" (FALSE) for each answer that doesn’t:
$B$2:$B$22=A26
The SUMPRODUCT function adds the products of the corresponding
items in the above Array and the SUBTOTAL Array.
The result is the number of times the answer specified in cell A26 occurs
for the filtered Question number (3).
¾ Solution:
With Student ID in cells H2:H6 and the answer criteria in cells I1:J1, use
the COUNTIF, INDIRECT, MATCH, and ROW functions as shown in the
following formula:
=COUNTIF(INDIRECT("B"&MATCH($H2,$A$2:$A$6)+ROW($A$2)-
1&":F"&MATCH($H2,$A$2:$A$6)+ROW($A$2)-1),I$1)
Explanation:
The MATCH function in the following expression returns the relative
position (row number) within cells A2:A6 of the ID specified in cell H2.
MATCH($H2,$A$2:$A$6)+ROW($A$2)-1
The row number of the first ID in column A (calculated by the ROW
function) is added to that position and 1 is subtracted from the result.
Thus, the above expression calculates the row number that contains the
answers of the student specified in cell H2.
The text "B", the calculated row number, the text ":F", and the calculated
row number again (returned by the second occurrence of the above
expression in the formula) are all joined into a single string.
That string represents the reference of the range that contains the answers
of the student specified in cell H2.
The INDIRECT function returns the reference indicated by that string.
Finally, the COUNTIF function returns the number of times the answer
specified in I1 appears within the reference returned by the INDIRECT
function.
Thus, it returns the count of questions answered Y (cell I1) by student 1
(cell H2).
In order to complete the summary table and return the results matching
each ID/answer combination, copy the formula to range I2:J6 (the
references of the cells containing the student ID and answer criteria will
update accordingly).
¾ Solution:
Use the SUMPRODUCT and MMULT functions as shown in the following
Array formula:
{=SUMPRODUCT(--(MMULT(--($B$2:$F$8=H2),{1;1;1;1;1})=I2))}
Explanation:
The following expression returns an Array consisting of TRUE for every
answer in cells B2:F8 that matches the criteria in cell H2 and FALSE for
every answer that doesn’t:
$B$2:$F$8=H2
The "--" sign converts each TRUE/FALSE in the Array to 1/0 accordingly.
The MMULT function returns the matrix product of the Array created
above and the following Array:
{1;1;1;1;1}
The result is an Array consisting of the number of times the answer
specified in cell H2 appears within each row in range B2:F8.
Each number in that Array, representing a row in cells B2:F8 is compared
with the number of times specified in cell I2. The result is an Array
consisting of TRUE for each number that matches the criteria in cell I2
and FALSE for every number that doesn’t:
The "--" sign converts each TRUE/FALSE in the array to 1/0 accordingly.
Thus, the Array consists of "1" for every student (row) in cells B2:F8 who
gave the answer specified in cell H2 as many times as specified in cell I2,
and "0" for every student who didn’t.
The SUMPRODUCT function adds all the values in that Array, and
returns the number of students in cells B2:F8 who gave a specific answer
(cell H2) a specific number of times (cell I2).
¾ Solution:
Use the SUM, MMULT, TRANSPOSE, and COLUMN functions as shown
in the following Array formula:
{=SUM((MMULT(--
($B$2:$E$6="X"),TRANSPOSE(COLUMN(B2:E6))^0)=1)*(B2:B6="X"))}
Enter the above formula in a cell under the first column of your matrix
(cell B8), and copy it across to the last column.
Explanation:
The MMULT function, using the TRANSPOSE and COLUMN functions,
returns an Array consisting of the number of "X" occurrences in each row
in cells B2:E6.
Each number in that Array is compared with "1", and the result is an Array
that consists of "1" (TRUE) for every number that equals 1 and "0" (FALSE)
for every number that doesn’t.
Hence, the Array consists of "1" for every row in the matrix that includes a
unique "X" (i.e. "X" appears only once within the row) and "0" for every
row that doesn’t.
The following expression returns an additional Array consisting of "1" for
every cell in column B that contains "X" and "0" for every cell that doesn’t.
B2:B6="X"
The corresponding values in the two Arrays created above are multiplied,
and the SUM function adds the results.
The number returned by the SUM function represents the number of cells
in column B that contain an "X" which is unique within the row.
¾ Solution:
Use the SUMPRODUCT function as shown in the following formula and
enter it in cell E3, then copy the formula to the entire grid (cells E3:J6):
=SUMPRODUCT(($A$2:$A$7=$D3)*($B$2:$B$7=E$2))
Explanation:
The following expression returns an Array consisting of "1" (TRUE) for
each letter in column A (cells A2:A7) that is identical to the one in cell
D3 and "0" (FALSE) for each letter that isn’t:
$A$2:$A$7=$D3
Similarly, the following expression returns an Array consisting of "1"
(TRUE) for each number in column B (cells B2:B7) that is equal to the one
in cell E2 and "0" (FALSE) for each number that isn’t:
$B$2:$B$7=E$2
The SUMPRODUCT function adds the products of the corresponding
items in the two Arrays created above.
The result represents the number of rows in the range A2:B7 that contain
the letter-number combination specified in cells D3 & E2.
In order to complete the counting grid and return the count matching
each letter/number combination shown in the range D2:J6, copy the
formula to cells E3:J6 (the references of the letter and number criteria will
adjust accordingly).
Chapter 7
Summing
¾ Solution:
Use the SUM function as shown in the following formulas:
1. =SUM(A:B 2:2)
2. =SUM(A:A 3:4)
3. =SUM(A:B 1:1,5:5)
Explanation:
To sum the values in cells at the intersection of ranges, leave a space
between the argument ranges in the SUM function instead of a comma.
¾ Solution:
1. Select a cell to contain the sum and type =SUM(
2. Select the tab of the first sheet to sum (January).
3. Hold the <Shift> key and then select the tab of the last sheet to sum
(April).
4. Select the cell to sum (A1).
5. Type ) and <Enter>.
These actions will create the following formula, which sums the same cell
(A1) from all four sheets:
=SUM(January:April!A1)
Explanation:
The SUM function adds all the values in the range "January:April!A1",
which consists of cell A1 from sheets "January, "February", "March", and
"April".
¾ Solution:
Use the SUM, IF, COUNT, and OFFSET functions as shown in the
following formula:
=SUM(B2:B7,(IF(COUNT(B9:B990)>0,OFFSET(B9,0,0,COUNT(B9:B990)),
0)))
Explanation:
The COUNT function returns the number of numeric values in cells
B9:B900, which is the number of numeric values added to List1.
The OFFSET function returns the reference of a range that starts at cell B9
and includes as many rows as the number returned by the COUNT
function.
If any numbers were added to the list (the number returned by the
COUNT function is greater than 0), the IF function returns the reference
created by the OFFSET function. Else, it returns 0.
The SUM function adds the values in cells B2:B7 with the values stored in
the range returned by the IF function.
¾ Solution:
Use the SUM and ABS functions as shown in the following Array formula:
{=SUM(ABS(A2:A8))}
Explanation:
The ABS function returns an Array consisting of the absolute
values of all the numbers in List1.
The SUM function adds all the numbers in that Array.
¾ Solution:
Use the SUBTOTAL function to sum each group in the range, and
then use the SUBTOTAL function to sum the values as shown in
the following formula:
=SUBTOTAL(9,A:A)
Explanation:
The SUBTOTAL function sum all values in the range except values
calculated by the SUBTOTAL formulas.
¾ Solution:
To cause the SUMPRODUCT formula to sum the values from a
range instead of counting them, add another argument to the
SUMPRODUCT formula that contains the range to sum (cells
C2:C9):
=SUMPRODUCT((A2:A9=1)*(B2:B9="A")*C2:C9)
¾ Solution:
Round all the numbers in cells C2:C4 to the nearest integer prior to
summing them.
Use the SUM and ROUND functions in following Array formula:
{=SUM(ROUND(C2:C4,0))}
Round all the numbers in column cells E2:E4 to thousands prior to
summing them.
Use the SUM and ROUND functions in the following Array formula:
{=SUM(ROUND(E2:E4,-3))}
Explanation:
Excel does not take number formatting into account when performing
mathematical calculations.
Instead, it operates on the entire number, using up to 15 significant digits,
regardless of how many digits are currently displayed.
Hence, the calculated sum in cell C5 matches the actual values found in
the cells, but does not match the numbers displayed.
In order for Excel to sum the numbers as they are displayed (rounded), we
must actually round all the numbers prior to summing them, rather than
just setting their format to display rounded numbers.
The ROUND function in the Array formula entered in cell C7 rounds
each of the numbers in cells C2:C4 to 0 decimal places (the nearest
integer) and returns the results in a single Array.
The SUM function adds all the values in that Array.
Thus, it sums all the numbers in cells C2:C4 after rounding each of them
to the nearest integer.
Similarly, the Array formula entered in cells E7 returns the sum of all the
numbers in cells E2:E4 after rounding each of them (using the ROUND
function) to -3 decimal places (thousands).
¾ Solution:
Use the SUMIF function as shown in the following formulas:
1. =SUMIF(A2:A7,"Excel",B2:B7)
2. =SUMIF(A2:A7,"Excel*",B2:B7)
3. =SUMIF(A2:A7,"*Excel",B2:B7)
4. =SUMIF(A2:A7,"*Excel*",B2:B7)
5. =SUMIF(A2:A7,"???",B2:B7)
Explanation:
The * sign: Any additional characters on the right/left ends of the string
are acceptable when searching for the specified criteria.
The ? Sign: Only strings of the same length as the number of "?"s will be
returned; any characters are acceptable.
¾ Solution:
Use the SUM, IF, ISNUMBER, FIND, VALUE, and LEFT functions as
shown in the following Array formula:
{=SUM(IF(ISNUMBER(FIND(C2,B2:B5)),VALUE(LEFT(B2:B5,FIND(C2,B2:
B5)-1)),0))}
Explanation:
The ISNUMBER and FIND functions are used to determine which of the
strings in column B contain the measurement type specified in cells
C2:C4.
For every string that contains the specified type, the IF functions returns
the result of the following expression:
VALUE(LEFT(B2:B5,FIND(C2,B2:B5)-1)
The FIND function returns the location (character number) of the
measurement string within the text in column B.
The LEFT function then extracts all the characters in the string up until
that location. Thus, extracting the numeric part of the string.
The VALUE function converts the numeric part of the string to a number.
The numbers extracted from each string in column B that contains the
specified measurement are then put in a single Array which is returned by
the IF function.
Finally, the SUM function adds all the numbers in that Array.
¾ Solution:
Use the SUM, VALUE, and SUBSTITUTE functions as shown in the
following Array formula:
{=SUM(VALUE(SUBSTITUTE(A2:A6,"T","")))}
Explanation:
The SUBSTITUTE function returns an Array of all the strings in column A,
with each having had the "T" removed.
The VALUE function converts the text values in that Array into numeric
values.
The SUM function adds all the values.
¾ Solution:
Use the SUM, VALUE, and SUBSTITUTE functions as shown in the
following Array formula:
{=SUM(VALUE(SUBSTITUTE(A2:A4," ","")))}
Explanation:
The SUBSTITUTE function returns an Array of all the strings in column A
after having had all redundant spaces removed.
The VALUE function converts the text values in that Array into numeric
values.
The SUM function adds all the values.
¾ Solution 1:
Use the SUM, IF, and ISNUMBER functions as shown in the following
Array Formula:
{=SUM(IF(ISNUMBER(A2:A5),(A2:A5)*((B2:B5=3)+(B2:B5=4))))}
Note:
It is most likely that the blank cell in column A is actually not empty,
but contains an invisible space.
Using the ISNUMBER and IF functions overcomes any errors.
¾ Solution 2:
Use the SUMIF function as shown in the following formula:
=SUMIF(B2:B5,3,A2:A5)+SUMIF(B2:B5,4,A2:A5)
Explanation:
The ISNUMBER function returns an Array, which includes a value of
"TRUE" for every cell in column A that contains a number and a "FALSE"
for every cell that does not contain one.
Based on the ISNUMBER results, the IF function returns an Array
containing the scores stored in all the cells that contain numbers in
column A, providing that their corresponding quarter in column B is 3 or
4 (2nd half).
The SUM function adds all the scores in that Array.
¾ Solution 1:
Use the SUMIF function as shown in the following formula:
=SUMIF(B2:B7,"<>",A2:A7)
Explanation:
The SUMIF function adds all the values in column A that have non-empty
corresponding cells in column B.
¾ Solution 2:
Use the SUMPRODUCT function as shown in the following formula:
=SUMPRODUCT(A2:A7*(B2:B7<>""))
Explanation:
The following expression creates an Array of TRUE/FALSE results:
B2:B7<>""
The Array includes a "1" (TRUE) for every non-empty cell in column B
and a "0" (FALSE) for every empty one.
That Array is then multiplied by another Array, which consists of all the
values in column A.
The SUMPRODUCT function adds the products of the corresponding
values in those two Arrays.
Thus, returning the sum of all the values in column A corresponding to
non-empty cells in column B.
¾ Solution:
Use the SUM and INDIRECT functions as shown in the following
formula:
=SUM(INDIRECT(E2&":"&F2))
Explanation:
The cell references in cell E2 (Range Beginning) and cell F2 (Range End)
are joined into a single string, with the ":" sign between them.
This creates a text value representing a range reference.
The INDIRECT function returns the range reference indicated by that text.
The SUM function adds all the values within that range.
¾ Solution:
Use the SUMPRODUCT, SUMIF, INDIRECT, and ROW functions as
shown in the following formula:
=SUMPRODUCT(SUMIF(INDIRECT("’Sheet"&ROW(INDIRECT("1:3"))&"’!
$A$1:$A$4"),A1,INDIRECT("’Sheet"&ROW(INDIRECT("1:3"))&"’!$B$1:$B
$4")))
Enter the above formula cell B2 of your Total Sheet, and copy it down the
column.
Explanation:
In the first argument of the SUMIF function (range) is an INDIRECT
function.
Using the ROW function and another INDIRECT function, it returns an
Array containing the references of the range A1:A4 in Sheet1, Sheet2, and
Sheet3.
The third argument of the SUMIF function (sum_range) is similar to the
first one.
In this case, the INDIRECT function returns an Array containing the
references of the range B1:B4 in Sheet1, Sheet2, and Sheet3.
For each of the three sheets, the SUMIF function adds the values in
column B for which the corresponding values in column A are identical
to the value entered in cell A1. The function then returns an Array
consisting of those three sums.
The SUMPRUDCT function adds all the values in that Array; thus
returning the total sum of the values from all three sheets.
¾ Solution:
Use the SUM, COLUMN, and INDIRECT functions as shown in the
following Array formula:
{=SUM((COLUMN(INDIRECT("A:Z"))<COLUMN(INDIRECT("A:A"))+A2)*
IF(ISNUMBER(’C:\My
Documents\[Book1.xls]Sheet1’!$A$3:$Z$3),’C:\My
Documents\[Book1.xls]Sheet1’!$A$3:$Z$3))}
Explanation:
The COLUMN and INDIRECT functions are used to return an Array
consisting of a TRUE for every column (A-Z) in Book1, Sheet1, Row 3 to
be included in the sum, and a FALSE for every column not to be included.
The results in that Arrays (TRUE/FALSE) are determined based on the
number of values to sum, entered in cell A2.
For every column for which TRUE was returned in the above Array, the IF
function returns the value stored in it, providing that the ISNUMBER
function determined that the value was a number.
Thus, an Array is created that contains all the numbers to sum.
Finally, the SUM function adds all the values in the Array.
¾ Solution:
Use the SUMIF function as shown in following formulas:
To sum negative numbers:
=SUMIF(A2:A7,"<0")
To sum positive numbers:
=SUMIF(A2:A7,">0")
Explanation:
The SUMIF function adds all the values in column A that meet the
specified criteria, that is, smaller or greater than 0.
¾ Solution:
Use the SUMIF function as shown in the following formula:
=SUMIF(A2:A6,"<>Jacket",B2:B6)
Explanation:
The SUMIF function adds all the values (Sales) in column B for which the
corresponding Item in column A is not "Jacket".
¾ Solution:
Use the SUMIF function as shown in the following formula:
=SUMIF($B$2:$F$5,A8,$C$2:$G$5)
Explanation:
The SUMIF function adds all the values in the range C2:G5 for which the
value to the left (cells B2:F5) matches the name specified in cell A8.
¾ Solution:
Use the SUMPRODUCT function as shown in the following formula:
=SUMPRODUCT((A1:A7="A")*(B1:B7="Customer1"),C1:C7)
Note:
Summing or counting according to multiple criteria cannot be
performed on entire column.
Therefore, in order to use the above formula, the column ranges must be
adjusted to specific ranges (i.e. A1:A10, A1:A2000, A1:A65000, etc.).
Explanation:
The first argument of the SUMPRODUCT formula is an Array returned by
the following expression:
(A1:A7="A")*(B1:B7="Customer1")
The Array contains a "1" (TRUE) for all the "A" values in column A
(Product Category) that have a corresponding Customer in column B of
"Customer1". "0" (FALSE) is returned for all other values in column A.
The second argument is an Array consisting of all the prices in column C.
The SUMPRODUCT function adds the products of the corresponding
values from those two Arrays.
Thus, totaling the prices of all the "Category A" products purchased by
"Customer1".
¾ Solution 1:
Use the SUMPRODUCT function as shown in the following formula:
=SUMPRODUCT(B2:B5,C2:C5)
¾ Solution 2:
Use the SUM function as shown in the following Array formula:
{=SUM((B2:B5)*(C2:C5))}
Explanation
) Explanation to Solution1:
The SUMPRODUCT function adds the products of the corresponding
values in cells B2:B5 (Array1) and cells C2:C5 (Array2).
Thus, each Amount is multiplied by its corresponding Price per Unit,
and the results are totaled.
) Explanation to Solution 2:
The following expression returns an Array consisting of the product of
each Amount in column B and its corresponding Price in column C.
(B2:B5)*(C2:C5)
The SUM function adds all the values in that Array.
We want a total of the calories gained last week by eating the food items
specified in column F.
¾ Solution 1:
Use the SUMPRODUCT function as shown in either of the following
formulas:
=SUMPRODUCT((A2:A7=F2)*(B2:B7))+SUMPRODUCT((C2:C7=F3)*(D2:
D7))
=SUMPRODUCT(--(A2:A7=F2),(B2:B7))+SUMPRODUCT(--
(C2:C7=F3),(D2:D7))
¾ Solution 2:
Use the SUMIF function as shown in the following formula:
=SUMIF(A2:A7,F2,B2:B7)+SUMIF(C2:C7,F3,D2:D7)
Explanation:
Second Formula:
The first argument of the first SUMPRODUCT function is an Array,
including a "TRUE" for every value in column A that matches the criteria
in cells F2, and a "FALSE" for every value that does not match the criteria.
The "--" sign, entered before the above expression, converts the TRUE and
FALSE values in that Array to "1" and "0" accordingly.
The second argument of the first SUMPRODUCT function is an Array
including all the values in column B (cells B2:B7).
The SUMPRODUCT function returns the sum of the products of the
corresponding items in those two Arrays (i.e. the sum of all the calorie
values that correspond with food items matching the criteria in cell F2).
Similarly, the second SUMPRODUCT function in that formula returns the
sum of all the calorie values (column D) corresponding with food items in
column C that match the criteria in cell F3.
Finally, the two sums are added together.
Note:
Putting the "*" operator between the two ranges in the
SUMPRODUCT function (as done in the first formula) is equivalent to
putting the "--" before the first range and separating it from the second
range with a comma (as done in the second formula).
¾ Solution:
Use the SUM function as shown in the following Array formula:
{=SUM((A2:A9="B")*(B2:B9<=2)*C2:C9)}
Explanation:
The following expression returns an Array containing all the scores in
column C that correspond with having Team in column A as "B" and
Game Number in column B as smaller than or equal to 2:
(A2:A9="B")*(B2:B9<=2)*C2:C9
The SUM function adds all the scores in that Array.
¾ Solution:
Use the SUM, OFFSET, and MATCH functions as shown in the following
formula:
=SUM(OFFSET(B2,0,0,MATCH(D2,A2:A8,0),1))
Explanation:
The MATCH function returns the position (row number) of the month
within cells A2:A8 that matches the month entered in cell D2.
The OFFSET function returns the reference of a range that starts at cell B2
and includes as many rows as the number returned by the MATCH
function.
The SUM function adds all the values (Total Expenses) in that range.
¾ Solution:
To retrieve income per month, use the SUMIF function as shown in
the following formula in cell B9:
=SUMIF($B$1:$M$1,$J$8,B3:M3)
To calculate the accumulated income up until the month indicated,
use the SUMIF function as shown in the following formula in cell C9:
=SUMIF($B$1:$M$1,"<="&$B$10,B3:M3)
To change the titles in cells B8:C8:
Use the INDEX function as shown in the following formulas:
To change the title in cell B8:
=INDEX(B2:M2,J8)&" "&"Income"
To change the title in cell C8:
="Accumulated Income Until" &" "& INDEX(B2:M2,J8)
Explanation:
) Income per Month Formula:
The SUMIF function adds all the values in cells B3:M3 (Income1
amounts) which have corresponding month number that match the
one entered in cell J8.
Thus, the Income1 amount for the specified month is returned.
) Accumulated Income Formula:
The SUMIF function adds all the values in cells B3:M3 (Income1
amounts) which have corresponding month numbers smaller than or
equal to the one entered in cell J8.
Thus, the accumulated sum of Income1 amounts up until the
specified month is returned.
) Title (cell B8) Formula:
The INDEX function returns the value in cells B2:M2 that is stored in
the position specified in cell J8.
¾ Solution:
Use the SUM, ROUNDUP, and MONTH functions as shown in the
following Array formula:
{=SUM((C2=ROUNDUP(MONTH($A$2:$A$9)/3,0))*$B$2:$B$9)}
Explanation:
The MONTH function returns an Array which contains the month number
matching each date in column A.
¾ Solution:
Use the SUMIF function as shown as shown in the following formula:
=SUMIF(A3:A7,B10,B3:B7)+SUMIF(D3:D7,B10,E3:E7)
Explanation:
The first SUMIF function adds all the values in column B (Hours Worked)
that have corresponding IDs (in column A) that match the one entered in
cell B10.
The second SUMIF function does the same thing for the Hours Worked in
column E and IDs in column D.
The two sums are then added together, creating a total of the hours
worked in both weeks.
¾ Solution 1:
Use the SUM and INDEX functions as shown in the following formula:
=SUM(INDEX($B$2:$M$2,3*A6-2):INDEX($B$2:$M$2,3*A6))
¾ Solution 2:
Use the SUM and OFFSET functions as shown in the following formula:
=SUM(OFFSET($B$2:$D$2,0,3*(A6-1)))
Explanation:
) Explanation to Solution 1:
The first INDEX function uses the batch number in cell A6 to
calculate the position (column number) of the first cell of that batch.
Based on that position, it returns the reference of the first cell of the
batch.
Similarly, the second INDEX function returns the reference of the last
cell of the batch.
The ":" sign between the two INDEX functions creates a reference of
the range containing the desired batch.
The SUM function adds all the values in that range.
) Explanation to Solution 2:
The OFFSET function offsets the range reference of the first batch
(cells B2:D2) by as many columns as calculated by the following
expression:
3*(A6-1)
Thus, it returns the reference of the range containing the desired
batch.
The SUM function adds all the values in that range.
¾ Solution:
Use the SUM, OFFSET, and COUNTA functions as shown in the
following formula:
=SUM(OFFSET($A$2,COUNTA($A$2:$A$7)-1,0,-B2))
Explanation:
The COUNTA function returns the number of values in column A.
The OFFSET function offsets the given reference (cell A2) down as many
rows as the number calculated by the COUNTA function minus 1, and
creates the reference of a range that ends at that point (the cell containing
the last value in List1) and includes as many rows as the number entered
in cell B2.
The SUM function adds all the values in that range.
¾ Solution:
Use the SUM, LARGE, ROW, and INDIRECT functions as shown in the
following Array formula:
{=SUM(LARGE($A$2:$A$11,ROW(INDIRECT("1:"&B2))))}
Explanation:
The text value "1:" and the number of values to sum (cell B2) are joined
into a single text value, representing a reference of the rows from "1" to
the number in cell B2.
The INDIRECT function returns the reference indicated by that text.
The ROW function returns an Array consisting of the row numbers of
each row included in that reference.
The LARGE function uses each of those row numbers as a value for kth
and returns an Array consisting of the kth largest number in column A for
each value of K.
The SUM function adds all the values in that Array.
¾ Solution:
Use the SUM, OFFSET, INDIRECT, ADDRESS, ROW, and COLUMN
functions as shown in the following formula:
=SUM(OFFSET(INDIRECT(ADDRESS(ROW(),COLUMN())),0,-1,1,-2))
Explanation:
The ADDRESS function, using the ROW() and COLUMN() functions,
returns a text value representing the reference of the current cell.
The INDIRECT function returns the reference indicated by that text value.
The OFFSET function returns the reference of a range that consists of the
two cells located to the right of that reference (current cell).
The SUM function adds the values in that range.
The last two arguments of the OFFSET function delineate the size of the
range (height& width).
When the range width of the OFFSET function is -2, the above formula
adds the previous 2 numbers to form the current number.
When the width is -3, the formula sums the previous 3 numbers, and so
on.
Chapter 8
List
¾ Solution:
To sort in ascending order, use the SMALL and ROW functions as
shown in the following formula (in cell B2):
=SMALL($A$2:$A$5,ROW()-ROW($B$2)+1)
To sort in descending order, use the LARGE and ROW functions as
shown in the following formula (in cell C2):
=LARGE($A$2:$A$5,ROW()-ROW($C$2)+1)
Explanation:
) Sort Ascending Formula (cell B2):
The ROW functions in the following expression return the row
numbers of the current cell and the first cell in the result column (cell
$B$2):
ROW()-ROW($B$2)
The result of this expression represents the number of values that have
been retrieved from List1 so far.
The SMALL function returns the kth smallest number in List1, where
kth is the number calculated by the above expression, plus 1.
Thus, it returns the smallest number in List1 that has not yet been
retrieved; resulting in an ascending list of numbers.
) Sort Descending Formula (cell C2):
The ROW functions in the following expression return the row
numbers of the current cell and the first cell in the result column (cell
$C$2):
ROW()-ROW($C$2)
The result of this expression represents the number of values that have
been retrieved from List1 so far.
The LARGE function returns the kth largest number in List1, where kth
is the number calculated by the above expression, plus 1.
Thus, it returns the largest number in List1 that has not yet been
retrieved; resulting in a descending list of numbers.
¾ Solution:
Enter the MODE function as shown in the following formula (in cell B2):
=MODE(A2:A15)
Then, use the MODE, IF, and COUNTIF functions as shown in the
following Array formula in cell B3 and copy it down the column until the
#N/A error is returned:
{=MODE(IF(COUNTIF($B$2:B2,$A$2:$A$15)=0,$A$2:$A$15))}
Explanation:
) First Formula (cell B2):
The MODE function returns the most common number in List1.
) Second Formula (cells B3:B6):
The COUNTIF function returns an Array consisting of the number of
times each value in List1 (cells A2:A15) matches one of the values
currently in column B (i.e. cells $B$2:B2).
A count of 0 represents a number in List1 that does not yet appear in
column B.
Any other count represents a number in List1 that has already been
added to column B.
The IF function returns an Array consisting of the values in List1
corresponding to each zero returned by the COUNTIF function, i.e.
all the numbers in List1 that have not yet been added to column B.
The MODE function returns the most common number in that Array.
Thus, the second most frequent number in List1 now appears in cell
B3.
Similarly, the third most frequent number will appear in cell B4, and
so on.
¾ Solution:
Use the OFFSET, COUNTA, and ROW functions as shown in the
following formula:
=OFFSET($A$2,COUNTA($A$2:$A$6)-ROW()+1,0))
Explanation:
The COUNTA function returns the number of values (non-blank cells) in
cells A2:A6.
The ROW function returns the row number of the current cell.
The calculated row number is then subtracted from the number of values,
and 1 is added to the result.
The OFFSET function offsets the reference of the first cell in the list (cell
$A$2) as many rows as the number calculated above.
Thus, the contents of the list are copied in reverse order.
¾ Solution:
Enter the RAND function as shown in each of the corresponding cells in
column A:
=RAND()
Explanation:
) First Formula (Column A):
The RAND function returns a random number between 0 and 1.
) Second Formula (Column C):
The ROW functions return the row numbers of the current cell and of
the first cell in the shuffled list (cell C2):
Subtracting these numbers represents the number of letters that have
currently been retrieved from List1 (cells B2:B9).
The LARGE function returns the kth largest random number from cells
A2:A9, where kth is the number calculated by the ROW expression,
plus 1.
Thus, in the first cell of the shuffled list (cell C2), the LARGE function
returns the largest random number, in the second cell (cell C3), it
returns the second largest random number, and so on.
The VLOOKUP function looks up column A for the number returned
by the LARGE function, and retrieves the corresponding value from
the second column (column B).
As the random values in column A change with each recalculation
(<F9> key), the order of the letters in the shuffled list will also change
accordingly.
¾ Solution:
Use the INDEX, MATCH, and COUNTIF functions as shown in the
following Array formula:
{=INDEX($A$2:$A$8,MATCH(0,COUNTIF($B$2:B2,$A$2:$A$8),0))}
Note:
The first cell in the unique list (column B) must remain empty.
The formula should be entered in the second cell and copied down
until the #N/A error is returned.
Explanation:
The COUNTIF function returns an Array consisting of the number of
times each value in the list (cells A2:A8) matches one of the values
currently in column B (i.e. cells $B$2:B2).
A count of 0 represents a value in the list that does not yet appear in
column B.
Any other count represents a value in the list that has already been added
to column B
The MATCH function returns the position of the first 0 within that Array.
The INDEX function returns the value stored in the same position in the
list.
Thus, the first value in the list that does not already appear in column B is
now added.
When the formula is copied to the other cells, the reference of the result
column (cells $B$2:B2) changes to include all the cells in column B
above the current cell.
¾ Solution:
Use the INDEX, SMALL, IF, COUNTIF, and ROW functions as shown in
the following Array formula:
{=INDEX($A$2:$A$7,SMALL(IF(COUNTIF($B$2:$B$7,$A$2:$A$7)=0,RO
W($A$2:$A$7),1000),ROW()-ROW($C$2)+1)-ROW($C$2)+1)}
Enter the formula in cell C2 and copy it down the column until the #REF!
error is returned.
Explanation:
The COUNTIF function returns an Array consisting of the number of
times each value in List1 (cells A2:A7) matches one of the values in List2
(cells B2:B7).
The IF function returns an Array consisting of the row number (calculated
by the ROW function) of each value in List1 for which the COUNTIF
function returned a count of 0 (i.e. values that don’t exist in List2), and the
number 1000 for every other value.
The ROW functions in the following expression return the row numbers
of the current cell and the first cell in the result column (cell $C$2):
ROW()-ROW($C$2)
The result of this expression represents the number of values that have
been retrieved from List1 so far.
The SMALL function returns the kth smallest number in the Array returned
by the IF function, where kth is the number calculated by the above
expression, plus 1.
Thus, it returns the row number of the first value in List1 that is not
common to List2 and has not yet been retrieved.
The row number of the first cell in the result column (cells $C$2) is then
subtracted from the row number returned by the SMALL function, and 1 is
added to the result.
The result of that calculation represents the position within List1 of the
first value that does not appear in List2 and that has not yet been
retrieved.
The INDEX function returns the value stored in that position in List1.
Thus, a list is created of all the values in List1 that are not common to
List2.
¾ Solution:
Use the INDEX, SMALL, IF, COUNTIF, and ROW functions as shown in
the following Array formula:
{=INDEX($A$2:$A$9,SMALL(IF(COUNTIF($B$2:$B$9,$A$2:$A$9)>0,RO
W($A$2:$A$9),1000),ROW()-ROW($D$2)+1)-ROW($D$2)+1)}
Enter the formula in cell D2 and copy it down the column until the #REF!
error is returned.
Explanation:
The COUNTIF function returns an Array consisting of the number of
times each value in List1 (cells A2:A9) matches one of the values in List2
(cells B2:B9).
The IF function returns an Array consisting of the row number (calculated
by the ROW function) of each value in List1 for which the COUNTIF
function returned a count greater than 0 (i.e. the value exists in List2), and
the number 1000 for every other value.
The ROW functions in the following expression return the row numbers
of the current cell and the first cell the result column (cell $D$2):
ROW()-ROW($D$2)
The result of this expression represents the number of common values
that have been retrieved so far.
The SMALL function returns the kth smallest number in the Array returned
by the IF function, where kth is the number calculated by the above
expression, plus 1.
Thus, it returns the row number of the first value in List1 that also exists in
List2 and has not yet been retrieved.
The row number of the first cell in the result column (cell $D$2) is then
subtracted from the row number returned by the SMALL function, and 1 is
added to the result.
The result of that calculation represents the position within List1 of the
first common value that has not yet been retrieved.
The INDEX function returns the value stored in that position in List1.
Thus, a list is created of all the values in List1 that also appear in List2.
¾ Solution:
Use the INDEX, SMALL, IF, and ROW functions as shown in the
following Array formula:
{=INDEX($A$2:$A$11,SMALL(IF($A$2:$A$11<>"
",ROW($A$2:$A$11),1000),ROW()-ROW($B$2)+1)-ROW($B$2)+1)}
Enter the formula in cell B2, and copy it down the column, until the
#REF! error is returned.
Explanation:
The IF function returns an Array consisting of the row number (calculated
by the ROW function) of each non-blank cell in List1 and the number
1000 for each blank cell.
The ROW functions in the following expression return the row numbers
of the current cell and the first cell in the result column (cell $B$2):
ROW()-ROW($B$2)
The result of that calculation represents the position within List1 of the
first non-blank cell that has not yet been retrieved.
The SMALL function returns the kth smallest number in the Array returned
by the IF function, where kth is the number calculated by the above
expression, plus 1.
Thus, it returns the row number of the first non-blank cell in List1 that has
not yet been retrieved.
The row number of the first cell in the result column (cell $B$2) is then
subtracted from the row number returned by the SMALL function, and 1 is
added to the result.
The result of that calculation represents the position of the first non-blank
cell that has not yet been retrieved from List1.
The INDEX function returns the value that is stored in that position in
List1.
Thus, a list of all the non-blank cells in List1 is created.
¾ Solution:
Use the INDEX, SMALL, IF, and ROW functions as shown in the
following Array formula:
{=INDEX($A$2:$A$8,SMALL(IF($A$2:$A$8>$B$2,ROW($A$2:$A$8)-
ROW($C$2)+1,100),ROW()-ROW($C$2)+1))}
Enter the formula in cell C2 and then copy it down the column until the
#REF! error is returned.
Explanation:
The IF function returns an Array consisting of the row number (calculated
by the ROW function) of each value in List1 that is greater than the
number in cell B2, and the number 100 for each value that isn’t.
The ROW functions in the following expression return the row numbers
of the current cell and the first cell in the result column (cell $C$2):
ROW()-ROW($C$2)
The result of this expression represents the number of values that have
been retrieved from List1 so far.
The SMALL function returns the kth smallest number in the Array returned
by the IF function, where kth is the number calculated by the above
expression, plus 1.
Thus, it returns the row number of the first value in List1 that is greater
than the number in cell B2 and has not yet been retrieved.
The row number of the first cell in the result column (cell $C$2) is then
subtracted from the row number returned by the SMALL function, and 1 is
added to the result.
The result of that calculation represents the position within List1 of the
first value that is greater than the number in cell B2 and that has not yet
been retrieved.
The INDEX function returns the value stored in that position in List1.
Thus, a list is created of all the values in List1 that are greater than the
number in cell B2.
¾ Solution:
Use the IF and OR functions as shown in the following formula:
=IF(OR((A2+1=A3),(A2-1=A1)),"Sequential","Not Sequential")
Explanation:
The OR function returns TRUE if the number in cell A2 plus 1 equals the
number succeeding it (cell A3), or if the number in cell A2 minus 1
equals the number preceding it (cell A1).
Thus, TRUE is returned if the number in cell A2 is sequential to either of
its immediate neighbors.
If TRUE is returned, the IF function returns the string "Sequential".
Otherwise, it returns "Not Sequential".
¾ Solution:
Use the IF, COUNTA, SUMPRODUCT, and COUNTIF functions as
shown in the following formula:
=IF(COUNTA(A2:A7)=SUMPRODUCT((A2:A7<>"
")/COUNTIF(A2:A7,A2:A7&"")),"No Duplicates","Duplicates")
The formula will return "Duplicates" if the list contains duplicate values,
otherwise it will return "No Duplicates".
Explanation:
The SUMPRODUCT function (using the COUNTIF function) returns the
number of unique values in List1.
The COUNTA function returns the total number of values (non-blank
cells) in List1.
These two results are then compared. If they are equal, the IF function
returns the string "No Duplicates". Otherwise, it returns "Duplicates".
¾ Solution:
Use the SUMPRODUCT function as shown in the following formula:
=SUMPRODUCT((B2=$B$2:$B$6)*(A2=$A$2:$A$6)*(C2=$C$2:$C$6))>1
Explanation:
The following expression returns an Array consisting of "1" (TRUE) for
every value in cells B2:B6 that equals the value in cell B2 and "0" (FALSE)
for every value that doesn’t:
B2=$B$2:$B$6
Similar expressions are used regarding columns A & C and the values
entered in cells A2 & C2.
The SUMPRODUCT function adds the products of the corresponding
values in all three Arrays.
Thus, a count is returned of all the rows in range A2:C6 that contain the
three values stored in cells A2:C2.
If that count is larger than 1 (i.e. the same combination of values appears
in more than one row), TRUE is returned. Otherwise, FALSE is returned.
¾ Solution:
Use the IF and COUNTIF functions as shown in the following formula:
=IF(COUNTIF($A$2:$A$8,A2)=1,"Unique",
COUNTIF($A$2:$A$8,A2)&" Duplicates")
Explanation:
The COUNTIF function returns the number of values in List1 (cells
A2:A8) that are equal to the one entered in cell A2.
If that number is equal to 1, the IF function returns the string "Unique".
Otherwise, it returns a string composed of the result of the COUNTIF
function and the text "Duplicates".
Transposing a List
Transposing an Entire Range of Data into a
Single Column
¾ Problem:
Transposing all the values from Data Range (cells B3:E5) into a single
column.
¾ Solution:
To process the values in Data Range from left to right (i.e. row by
row):
Use the OFFSET, INT, ROW, and MOD functions as shown in the
formula in cell H3:
=OFFSET($B$3,INT((ROW()-ROW($H$3))/4),MOD(ROW()-
ROW($H$3),4))
To process the values in Data Range from top to bottom (i.e. column
by column):
Use the OFFSET, MOD, ROW, and INT functions as shown in the
following formula in cell I3:
=OFFSET($B$3,MOD(ROW()-ROW($I$3),3),INT((ROW()-
ROW($I$3))/3))
Explanation:
) Left to Right Formula (cell H3):
The ROW functions in the following expression return the row
numbers of the current cell and the first cell in the result column (cell
$H$3):
ROW()-ROW($H$3)
The result of this expression represents the number of values that have
been retrieved from Data Range so far, and is used to calculate the
row_num and column_num arguments of the OFFSET function.
row_num:
The number calculated by the ROW functions is divided by 4 (the
number of values in each row of Data Range), and the INT function
rounds the result to the nearest integer. The result represents the
number of full rows in Data Range that have been retrieved so far.
column_num:
The MOD function divides the number calculated by the ROW
functions by 3 (the number of values in each column of Data Range),
and returns the remainder. The result represents the number of values
retrieved so far from the row that is currently being processed.
The OFFSET function offsets the reference of the first cell in Data
Range (cell B3) by as many rows and columns as the numbers
calculated by the INT and MOD functions.
Thus, each of the values in the first row is processed, and then the
values in the second row, and so on.
) Top to Bottom Formula (cell I3):
The ROW functions in the following expression return the row
numbers of the current cell and the first cell in the result column
($l$3):
ROW()-ROW($I$3)
The result of this expression represents the number of values that have
been retrieved from Data Range so far, and is used to calculate the
row_num and column_num arguments of the OFFSET function.
row_num:
The number calculated by the ROW functions is divided by 3 (the
number of values in each column of Data Range), and the INT
function rounds the result to the nearest integer. The result represents
the number of full columns in Data Range that have been retrieved so
far.
column_num:
The MOD function divides the number calculated by the ROW
functions by 4 (the number of values in each row of Data Range), and
returns the remainder. The result represents the number of values
retrieved so far from the column that is currently being processed.
The OFFSET function offsets the reference of the first cell in Data
Range (cell B3) by as many rows and columns as the numbers
calculated by the INT and MOD functions.
Thus, each of the values in the first column is processed, then the
values in the second column, and so on.
¾ Solution:
Use the OFFSET, ROW, and COLUMN functions as shown in the
following formula in cell C2:
=OFFSET($A$2,(ROW()-ROW($C$2)+1)*3-3+COLUMN()-
COLUMN($C$2),0)
Copy the formula across to D2 & E2, and then copy all three cells down
columns C:E.
Explanation:
The ROW and COLUMN functions return the row and column numbers
of the current cell and the first cell in the result range (cell C2).
Those numbers are used to calculate the position of the current cell
within the result range.
Based on that position and the number of cells to be transposed into each
row (3), the formula calculates the number of values that have been
retrieved from List1 so far (i.e. if the current cell was cell D2, the result
would be 1).
The OFFSET function offsets the reference "$A$2" (the first cell in List1) as
many rows as the number calculated above.
¾ Solution:
Use the SMALL and COLUMN functions as shown in the following
formula and enter the formula in cells E1:I1:
=SMALL($A$2:$A$6,COLUMN()-COLUMN($E$1)+1)
Then, use the INDEX and MATCH functions as shown in the following
formula and enter the formula in cells E2:I2:
=INDEX($B$2:$B$6,MATCH(E1,$A$2:$A$6,0))
Explanation:
) Pay Date Formula (cells E1:I1):
The COLUMN functions in the following expression return the
column numbers of the current cell and the first cell in the result row
(cell $E$1):
COLUMN()-COLUMN($E$1)
The result of this expression represents the number of pay dates that
have been retrieved from cells A2:A6 so far.
The SMALL function returns the kth earliest date in cells A2:A6,
where kth is the number calculated by the above expression, plus 1.
Thus, it returns the earliest pay date that has not yet been retrieved;
resulting in an ascending list of dates in row 1.
) Payment Formula (cells E2:I2):
The MATCH function returns the position (row number) within cells
A2:A6 of the date returned into E1.
The INDEX function returns the payment stored at the same position
within cells B2:B6.
Thus, the payment matching each date in row 1 is returned into row 2.
Alternative solution:
Select cells C2:F2 and enter the TRANSPOSE function as shown in the
following Array formula:
{=TRANSPOSE(A2:A5)}
Explanation:
) Transposing from a Column into a Row:
INDEX and COLUMN Formula:
The COLUMN functions in the following expression return the
column numbers of the current cell and of the first cell in the result
row (cell $C$2).
COLUMN()-COLUMN($C$2)+1
The result of that expression represents the position (serial number) of
the value to be retrieved from List1 (cells A2:A5).
The INDEX function returns the value stored in that position in List1.
When the formula is copied to the next cell, the result of the above
expression increases by 1 (with respect to the column number of the
current cell), therefore, the formula returns the next value in List1.
) TRANSPOSE Array Formula:
The TRANSPOSE function returns an Array that is the transposed
version of the Array representing List1 (cells A2:A5).
As the values in List1 are arranged in a column, the values in the
Array returned by the TRANSPOSE function are arranged in a row.
That Array is returned into cells C2:F2 (selected on entering the
formula).
) Transposing from a Row into a Column:
INDEX and ROW Formula:
The ROW functions in the following expression return the row
numbers of the current cell and of the first cell in the result column
(cell $H$10).
ROW()-ROW($H$10)+1
The result of that expression represents the position (serial number) of
the value to be retrieved from List2 (cells B10:F10).
The INDEX function returns the value stored in that position in List2.
When the formula is copied to the next cell, the result of the above
expression increases by 1 (with respect to the row number of the
current cell), therefore, the formula returns the next value in List2.
) TRANSPOSE Array Formula:
The TRANSPOSE function returns an Array that is the transposed
version of the Array representing List2 (cells B10:F10).
As the values in List2 are arranged in a row, the values in the Array
returned by the TRANSPOSE function are arranged in a column.
That Array is returned into cells H10:H14 (selected on entering the
formula).
Chapter 9
Miscellaneous Calculation
& Math
Averaging Values
Calculating Average Annual Growth
¾ Problem:
Columns A & B show annual profits for a number of years.
We want to calculate the average rate at which profits grew each year.
¾ Solution:
Use the AVERAGE function in the following Array formula:
{=AVERAGE((B3:B5-B2:B4)/B2:B4)}
Explanation:
An annual growth rate is calculated by subtracting last year’s profit
from this year’s profit, and dividing the result by last year’s profit.
The following expression returns an Array consisting of the difference
between each profit in the years 2002-2004 (cells B3:B5) and the
profit in the previous year (cells B2:B4):
B3:B5-B2:B4
¾ Solution:
Use the AVERAGE function in the following Array formula:
{=AVERAGE(B3:B7-B2:B6)}
Explanation:
The following expression calculates the difference between each of the
cells B3:B7 and the cell above it (cells B2:B6):
B3:B7-B2:B6
Thus, creating an Array containing the number of centimeters the child
grew each year.
The AVERAGE function returns the average of all the values in that Array,
which is the average number of centimeters the child grew each year.
¾ Solution:
Use the IF and AVERAGE functions in the following Array formula:
{=AVERAGE(IF(A2:A7>B2,A2:A7))}
Explanation:
The following expression returns an Array consisting of TRUE for every
value in column A that is greater than the value in cell B2, and FALSE for
every value that isn’t:
A2:A7>B2
The IF function returns an Array consisting of the values in column A
(cells A2:A7) for which TRUE was returned by the above expression.
Thus, an Array is returned consisting of the prices in column A that are
higher than the criteria in cell B2.
The AVERAGE function returns the average of all the values in that Array.
¾ Solution 1:
To calculate the average difference in dollar amount, use the AVERAGE
function in the following Array Formula:
{=AVERAGE(A2:A5-B2:B5)}
¾ Solution 2:
To calculate the average difference in dollar amount, use the SUM and
COUNT functions in the following formula:
=(SUM(A2:A5)-SUM(B2:B5))/COUNT(A2:A5)
¾ Solution 3:
To calculate the average difference in percentage, use the AVERAGE
function in the following Array formula:
{=AVERAGE((A2:A5/B2:B5-1)*100)}
Explanation:
) Explanation to Solution 1:
The following expression returns an Array consisting of the difference
between each value in cells A2:A5 (List Price) and the corresponding
value in cells B2:B5 (Sale Price):
A2:A5-B2:B5
The AVERAGE function returns the average of all the values in that
Array.
Thus, calculating the average difference between List Price and Sale
Price.
) Explanation to Solution 2:
The first SUM function adds all the values in cells A2:A5 (List Prices).
The second SUM function adds all the values in cells B2:B5 (Sale
Prices).
The sum of the Sale Prices is then subtracted from the sum of the List
Prices, returning the total difference between all List Prices and all
Sale Prices.
Finally, that difference is divided by the total number of prices in cells
A2:A5 (returned by the COUNT function), returning the average
difference between List Price and Sale Price.
) Explanation to Solution 3:
The following expression divides each value in cells A2:A5 (List Price)
by the corresponding value in cells B2:B5 (Sale Price) and subtracts 1
from each result:
A2:A5/B2:B5-1
Thus, an Array is created that consists of the difference rate between
each List Price and its corresponding Sale Price.
Each value in that Array is then multiplied by 100 to convert the rates
to percentages.
The AVERAGE function returns the average of all the values in the
Array.
Thus, calculating the average difference in percentage between List
Price and Sale Price.
¾ Solution:
Use the AVERAGE and IF functions in the following Array formula:
{=AVERAGE(IF($A$2:$A$7=C2,$B$2:$B$7))}
Explanation:
The IF function returns an Array consisting of all the numbers in List2
(cells B2:B7) that have corresponding values in List1 (cells A2:A7) that are
equal to the value in cell C2.
The AVERAGE function returns the average of the numbers in that Array.
¾ Solution:
Use the TRIMMEAN function as shown in the following formula:
=TRIMMEAN(A2:A11,0.2)
Explanation:
The TRIMMEAN function returns the mean of the interior of a data set.
The first argument of this function is the data set to average.
The second argument is the percentage of top and bottom values to be
excluded from the calculation.
Thus, the above TRIMMEAN function will average the middle 80% of the
values in cells A2:A11; excluding both the top 10% (500) and the bottom
10% (0).
¾ Solution 1:
Use the AVERAGE and IF functions as shown in the following Array
Formula:
{=AVERAGE(IF(A2:A6="No",B2:B6))}
¾ Solution 2:
Use the SUMIF and COUNTIF functions as shown in the following
formula:
=SUMIF(A2:A6,"No",B2:B6)/COUNTIF(A2:A6,"No")
Explanation:
) Explanation to Solution 1:
The IF function returns an Array consisting of all the values (Prices) in
cells B2:B6 for which the corresponding string in cells A2:A6 is "No".
The AVERAGE function returns the average of all the values in that
Array.
Thus, calculating the average of all the prices in column B on which
there is no discount.
) Explanation to Solution 2:
The SUMIF function adds all the values in cells B2:B6 for which the
corresponding strings in cells A2:A6 are "No".
Similarly, the COUNTIF function returns the number of values in cells
B2:B6 for which the corresponding strings in cells A2:A6 are "No".
The sum calculated by the SUMIF function is then divided by the
count returned by the COUNTIF function, returning the average of all
the values in cells B2:B6 for which the corresponding strings in A2:A6
are "No".
Thus, calculating the average of all the prices in column B on which
there is no discount.
¾ Solution:
Use the AVERAGE, IF, and WEEKDAY functions in the following Array
formula:
{=AVERAGE(IF(WEEKDAY(A2)=WEEKDAY($A$2:$A$16),$C$2:$C$16)}
Explanation:
The first WEEKDAY function in the following expression returns a serial
number (1-7) that represents the day of the week corresponding with the
date in cell A2:
WEEKDAY(A2)=WEEKDAY($A$2:$A$16)
¾ Solution:
Use the AVERAGE, IF, and LARGE functions in the following Array
formula:
{=AVERAGE(IF($A$2:$A$65000>=LARGE($A$2:$A$65000,D2),$B$2:$B
$65000))}
Explanation:
The LARGE function returns the K largest number in column A (the kth
most recent date), where kth is the Number of Games to Average in cell
D2.
The IF function returns an Array consisting of all the scores in column B
that have a corresponding date in column A later than or equal to the one
returned by the LARGE function.
Thus, an Array is returned that contains the scores of the kth most recent
games.
The AVERAGE function returns the average of the values in that Array.
¾ Solution:
Use the SUM, MIN, and COUNT functions in the following formula:
=(SUM(A2:B5)-MIN(A2:B5))/(COUNT(A2:B5)-1)
Explanation:
The SUM function adds all the values in range A2:B5.
The MIN function returns the minimum number in that range.
As the minimum value is to be excluded in the calculation, the number
returned by the MIN function is subtracted from the sum returned by the
SUM function.
The result is then divided by the number of values in the range
(calculated by the COUNT function) minus 1 (because the minimum
value is excluded from the sum).
Thus, the formula returns the average of all the numbers in range A2:B5
except for the minimum.
¾ Solution:
Use the AVERAGE, IF, MOD, and ROW functions in the following Array
formula:
{=AVERAGE(IF((MOD(ROW($B$2:$B$10)-
ROW($B$2)+1,C2))=0,$B$2:$B$10))}
Explanation:
The first ROW function in the following expression returns the row
number of each cell in cells B2:B10:
ROW($B$2:$B$10)-ROW($B$2)+1
The second ROW function returns the row number of the first cell in the
list (cell B2).
Those row numbers are used by the above expression to calculate an
Array of serial numbers matching each cell in cells B2:B10.
The MOD function divides each of the serial numbers in the Array by the
N value in cell C2 (4), and returns an Array consisting of the remainder of
each calculation.
The IF function returns an Array consisting of all the values in cells
B2:B10 that have serial numbers that are divisible by N (i.e. the
remainder returned by the MOD function is 0).
The AVERAGE function returns the average of all the values in that Array,
i.e. the average of the values from every nth (4th) line in the list.
¾ Solution:
Use the AVERAGE, IF, MOD, and ROW functions as shown in the
following Array formula:
{=AVERAGE(IF((MOD(ROW($A$2:$A$13)-
ROW($A$2)+1,C2)=0)*($A$2:$A$13<>0),$A$2:$A$13))}
Explanation:
The first ROW function in the following expression returns the row
number of each cell in List1 (cells A2:A13):
ROW($A$2:$A$13)-ROW($A$2)+1
The second ROW function returns the row number of the first cell in the
list (cell A2).
Those row numbers are used by the above expression to calculate an
Array of serial numbers matching each cell in List1.
The MOD function divides each of the serial numbers in that Array by the
N value in cell C2, and returns an Array consisting of the remainder of
each calculation.
The following expression returns an additional Array consisting of TRUE
for every value in List1 that is not equal to 0 and FALSE for every other
value:
$A$2:$A$13<>0
The IF function returns an Array consisting of the values in List1 for which
TRUE was returned by the above expression (non-zeros) and for which
¾ Solution:
Use the AVERAGE, IF, MOD, COLUMN, and CELL functions in the
following Array formula:
{=AVERAGE(IF((MOD(COLUMN(B2:K2)-
CELL("col",B2)+1,E4)=0)*(B2:K2<>0),B2:K2))}
Explanation:
The COLUMN function in the following expression returns the column
number of each numeric value in row 2 (cells B2:K2):
COLUMN(B2:K2)-CELL("col",B2)+1,
The CELL function returns the column number (specified by using the
string "col" as the first argument of the function) of the first numeric value
in the row (cell B2).
Those column numbers are used by the above expression to calculate an
Array of serial numbers matching each numeric value in row 2.
The MOD function divides each of the serial numbers in that Array by the
N value in cell E4, and returns an Array consisting of the remainder of
each calculation.
The following expression returns an additional Array consisting of TRUE
for every numeric value in row 2 that is not equal to 0 and FALSE for
every other value:
B2:K2<>0
The IF function returns an Array consisting of the values in row 2 for
which TRUE was returned by the above expression (non-zeros) and for
which the serial numbers (calculated above) were divisible by N (i.e. the
remainder returned by the MOD function is 0).
The AVERAGE function returns the average of all the values in that Array.
Thus, an average is calculated for every nth value in row 2, excluding
zeros.
¾ Solution:
Use the MIN and INDIRECT functions in the following formula:
=MIN(INDIRECT("$A$2:A"&B2))
Explanation:
The text "$A$2:A" and the row number stored in cell B2 are joined into a
single string.
¾ Solution 1:
Use the MAX, LEFT, TEXT, and MIN functions in the following formula:
=MAX(A2:B2)*LEFT(TEXT(MIN(A2:B2)/MAX(A2:B2),"0000000/0000000"),7)
¾ Solution 2:
Use the LCM function in the following formula:
=LCM(A2:B2)
Explanation:
) Explanation to Solution 1:
The MIN function returns the minimum value in cells A2:B2, i.e. the
smaller number of that pair.
Similarly, the MAX function (the second one in the formula) returns
the larger number of the pair.
The smaller number is then divided by the larger number. The TEXT
function formats the result as "0000000/0000000", and converts it to
text.
The result of the TEXT function is a string representing the reduced
fraction created by the above calculation.
Hence, the string "0000002/0000003" is returned for the values in
cells A2:B2, "0000005/0000006" is returned for the values in cells
A3:B3, and so on.
The LEFT function returns the 7 leftmost characters of that string, i.e.
the numerator of the reduced fraction.
Finally, the larger number in cells A2:B2 (returned by the first MAX
function in the formula) is multiplied by the number represented by
the result of the LEFT function.
The result of that calculation is the lowest common multiple of the
numbers in cells A2:B2.
) Explanation to Solution 2:
The LCM function returns the least common multiple of the numbers
in cells A2:B2.
¾ Solution:
Use the LARGE and SMALL functions in the following formulas:
To find 2nd largest number enter:
=LARGE(A2:A8,2)
To find 3rd smallest number enter:
=SMALL(A2:A8,3)
Explanation:
The LARGE and SMALL functions return the kth largest/smallest number
in a data set.
The first argument of those functions is the data set (range reference/
Array).
The second argument is the number to be used as K.
¾ Solution:
Use the MAX, LEFT, and TEXT functions in the following Array formula:
{=MAX((LEFT(A2:A6,2)=TEXT(C2,"@"))*A2:A6)}
Explanation:
The LEFT function extracts the two leftmost characters of each string in
cells A2:A6 (the first two digits).
The TEXT function formats the number in cell C2 as "@" and converts it to
text.
The text, representing the criteria in cell C2, is then compared with the
two first digits of each string in column A (extracted by the LEFT function).
¾ Solution:
Use the LARGE function in the following Array formula:
{=LARGE(($B$2:$B$6=E2)*($C$2:$C$6),2)}
Explanation:
The following expression returns an Array consisting of "1" (TRUE) for
each team name in cell B2:B6 that equals the team criteria in cell E2 and
"0" (FALSE) for each team name that doesn’t.
$B$2:$B$6=E2
Each value in that Array, representing a team name in column B, is then
multiplied by the corresponding score from column C.
Thus returning an Array containing all the Scores of the Team specified in
cell E2, and zeros for the scores of all other teams.
The LARGE function returns the 2nd largest number in that Array, which
is the 2nd highest score by the team specified in cell E2.
If the maximum value found does not meet the above criteria, the formula
should look for the next largest number until finding the largest number
matching criteria.
¾ Solution:
Use the MAX functions in the following Array Formula:
{=MAX(MAX((A2:A5>C2)*A2:A5),MAX((B2:B5>C3)*B2:B5))}
Explanation:
The following expression returns an Array consisting of "1" (TRUE) for
each number in List1 that is greater than the criteria in cell C2 and "0"
(FALSE) for each number that isn’t:
A2:A5>C2
Each value in that Array is then multiplied by the number it represents in
List1.
Thus returning an Array consisting of all the numbers in List1 that meet
the criteria in cell C2 and zeros for the ones that don’t.
The MAX function (the second one in the formula) returns the maximum
value in that Array, which is the largest number in List1 that is greater
than the criteria in cell C2.
Similarly, the third MAX function in the formula returns the largest
number in List2 that is greater than the criteria in cell C3.
The first MAX function in the formula returns the larger of the two
numbers returned by the second and third MAX functions.
Rounding Values
Rounding Prices to the Nearest Nickel, Dime,
Quarter and Dollar
¾ Problem:
Rounding the prices in column A to the nearest nickel (5 cents), dime (10
cents), quarter (25 cents), and dollar.
¾ Solution:
Use the ROUND function in the following formulas:
Nearest Nickel Formula =ROUND(A2*20,0)/20
Nearest Dime Formula =ROUND(A2*10,0)/10
Nearest Quarter Formula =ROUND(A2*4,0)/4
Nearest Dollar Formula =ROUND(A2,0)
Explanation:
Nearest Nickel Formula:
The price in cell A2 is multiplied by 20 (representing the number of
nickels in a dollar).
The ROUND function rounds the result of the calculation to the nearest
integer (0 decimal places).
Finally, the number returned by the ROUND function is divided by 20
(representing the number of nickels in a dollar).
Thus, the formula rounds the price in cell A2 to the nearest nickel.
¾ Solution:
Step 1: Calculate the first payment by dividing the price by 5 and
rounding the result.
Use the ROUND function in the following formula:
=ROUND(B1/5,2)
Step 2: Calculate each remaining payment.
Use the ROUND, SUM, and ROW functions in the following
formula:
=ROUND(($B$1-SUM($B$2:B2))/(5-ROW()+ROW($B$2)),2)
Explanation:
In order to find the 5 similar payments, we have to calculate each
payment by dividing the current price (original price - payments already
calculated) by the number of remaining payments (those not yet
calculated).
) First Payment Formula:
The price in cell B1 is divided by 5 (the total number of payments).
The ROUND function rounds the result to 2 decimal places.
) Formula for Each Remaining Payment:
The SUM function adds all the values in the range between cell $B$2
(the first payment) and the cell above the current one in column B
(range $B$2:B2).
Thus, it calculates the sum of all the payments already calculated.
That sum is then subtracted from the original price in cell B1,
returning the current price.
The current price is then divided by the number of remaining
payments, calculated by subtracting the row number of the current
cell (returned by the first ROW function) from the total number of
payments (5) and adding the row number of the first payment
(calculated by the second ROW function).
Finally, the ROUND function rounds the result of that calculation to
2 decimal places.
¾ Solution:
To calculate Retail Price use the ROUND function in the following
formula:
=ROUND(A2/(1+7.75%),2)
To calculate Sales Tax use the ROUND function in the following formula:
=ROUND(7.75%*B2,2)
Explanation:
) Retail Price Formula:
The Total Price in cell A2 is divided by 107.75% (1+7.75%).
The result of that calculation is the Retail Price (excluding Sales Tax)
for the Total Price in cell A2.
The ROUND function rounds the result to 2 decimal places.
¾ Solution:
To round up, use the CEILING function in the following formula:
=CEILING(A2,50)
To round down, use the FLOOR function in the following formula:
=FLOOR(A2,50)
Explanation:
) CEILING Formula:
The CEILING function rounds the number in cell A2 up to the nearest
multiple of 50.
) FLOOR Formula:
The FLOOR function rounds the number in A2 down to the nearest
multiple of 50.
¾ Solution:
Use the IF, MOD, and ROUND functions in the following formula:
=IF(MOD(A2,1)=0.5,A2,ROUND(A2,0))
Explanation:
The MOD function divides the number in cell A2 by 1 and returns the
remainder.
If that remainder is 0.5 (the number in cell A2 has "5" in the first decimal
place), the IF function returns the original number from A2.
¾ Solution:
Use the ROUND, LEFT, FIND, and MID functions in the following
formula:
=ROUND(LEFT(A2,FIND("<>",A2)-
1),3)&"<>"&ROUND(MID(A2,FIND("<>",A2)+2,255),3)
Explanation:
The FIND function returns the relative position (character number) of the
text "<>" within the string in cell A2.
The LEFT function extracts all the characters in cell A2 that are to the left
of that position (up to the position returned by the FIND function minus
1).
Thus returning the left number of the string in cell A2.
The ROUND function (the first one in the above formula) rounds that
number to 3 decimal places.
The MID function extracts all the characters in cell A2 that are to right of
"<>" sign (starting at the position returned by the FIND function plus 2).
The number 255, used as the third argument of the MID function, is for
the maximum number of characters that Excel can hold in one string.
Thus, the MID function returns the right number of the string in cell A2.
The ROUND function (the second one in the above formula) rounds that
number to 3 decimal places.
Finally, the number returned by the first ROUND function is joined with
the text "<>" and with the number returned by the second ROUND
function.
Hence, the formula creates a new string which incorporates the rounded
version of the numbers from the original string.
¾ Solution:
Use the ROUNDUP function in the following formula:
=ROUNDUP(A2/B2,0)*B2
Explanation:
The number stored in cell A2 is divided by the corresponding number in
cell B2.
The ROUNDUP function rounds the result up to the nearest integer (0
decimal places).
The number returned by the ROUNDUP function is then multiplied by
the number in cell B2.
Thus, the formula rounds the number in cell A2 up to the nearest value
that makes it divisible by cell B2.
Ranking Values
Ranking a List of Numbers
¾ Problem:
Columns A & B list the names of the players who took part in the last
game and their respective scores.
We want to rank all the scores, in both descending and ascending order.
¾ Solution:
To rank the scores in descending order (labeling the highest score as
1), use the RANK function in the following formula:
=RANK(B2,$B$2:$B$9,0)
To rank the scores in ascending order (labeling the lowest score as 1),
use the RANK function in the following formula:
=RANK(B2,$B$2:$B$9,1)
Explanation:
The RANK function returns the rank of the number stored in cell B2
within the list of numbers in cells B2:B9.
The third argument of the RANK function represents the order by which
the numbers in the list are ranked.
0 or omitted represents a descending order (labeling the largest number as
1), and 1 represents an ascending order (labeling the smallest number as 1).
¾ Solution:
Use the RANK, OFFSET, and COUNTA functions in the following
formula:
=RANK(A4,OFFSET($A$4,0,0,COUNTA($A$4:$A$9),1))
Explanation:
The COUNTA function returns the number of values (non-blank cells) in
cells A4:A9.
The OFFSET function returns the reference of a range that starts at cell A4
(the first cell in the list) and includes as many rows as the number
calculated by the COUNTA function.
That reference represents the range that currently includes numbers to
rank.
As the result of the COUNTA function changes upon the removal or
addition of numbers to and from the list, the reference returned by the
OFFSET function will update accordingly to exclude/include only those
cells in the range.
The RANK function returns the rank of the number stored in cell A4
within the range returned by the OFFSET function (labeling the largest
number as 1).
¾ Solution:
Use the CHOOSE and RANK functions in the following formula:
=CHOOSE(RANK(B2,$B$2:$B$6),15%,12%,10%,8%,5%)*B2
Explanation:
The RANK function returns the rank of the Sales Total in cell B2 within
the totals listed in cells B2:B6 (labeling the highest total as 1).
The CHOOSE function returns the nth member of the list of percentages
in the formula (15%,12%,10%,8%,5%) where N is the number returned
by the RANK function.
Thus, it returns the percentage that matches the ranking of the total in cell
B2, based on the scheme listed above.
Finally, the percentage returned by the CHOOSE function is multiplied by
the total in cell B2.
The result is the commission for that total.
Random Calculation
Selecting a Set of Random Numbers, Avoiding
Duplicates
¾ Problem:
Selecting a set of 5 random numbers between 1 and 10, without getting
duplicates.
¾ Solution:
In Data Range (A1:C11):
Step 1: Enter RAND function in column A:
=RAND()
Step 2: Enter the following RANK formula in column B:
=RANK(A2,$A$2:$A$11)
¾ Solution:
Step 1: To retrieve Num1, use the INT and RAND functions in the
following formula in cell A2:
=INT(RAND()*30)+1
This ensures an upper limit of 30 for the number generated.
Step 2: To retrieve Num2, use the INT and RAND functions in the
following formula in cell B2:
=INT(RAND()*A2)
This ensures the number generated is smaller than Num1.
Explanation:
) First Formula (Num1 in cell A2):
The RAND function returns a random number.
That number is multiplied by 30 and the INT function rounds down
the result to the nearest integer.
1 is then is added to the result of the INT function.
Note:
Num1 and Num2 will automatically change upon recalculation
(<F9> key).
¾ Solution:
Use the INDEX and RANDBETWEEN functions in the following formula:
=INDEX(A1:C4,RANDBETWEEN(1,4),RANDBETWEEN(1,3))
Explanation:
The first RANDBETWEEN function returns a random number between 1
and 4 (the number of rows in range A1:C4).
Note:
The value retrieved by the formula will automatically change upon
recalculation (<F9> key).
¾ Solution:
Use the INDEX, ROUND, RAND, and COUNTA functions in the
following formula:
=INDEX(A2:A7,ROUND(RAND()*COUNTA(A2:A7),0))
Note:
The value returned by the formula will change with each
recalculation (<F9> key).
Explanation:
The COUNTA function returns the number of values (non-blank cells) in
List1 (cells A2:A7).
The RAND function returns a random number between 0 and 1.
Those two numbers are multiplied together and the result rounded to the
nearest integer (0 decimal places) by the ROUND function.
Thus, a random number is returned that is between 0 and the number of
values in List1, which represents a random position (row number) in List1.
The INDEX function returns the value that is stored in that random
position.
Hence, it returns a random number from the list.
Miscellaneous Calculation
Creating a Dynamic Inventory List Based on
Daily Sales
¾ Problem:
Columns A & B contain a log of all the sales from a particular day.
Each row consists of the name of an item and the quantity sold.
¾ Solution:
Use the SUMIF function in the following formula:
=E2-SUMIF($A:$A,D2,$B:$B)
Explanation:
The SUMIF function adds all the values in column B (Quantity Sold) for
which the corresponding value in column A (Item) equals the value in
cell D2.
Thus, it returns the total quantity sold for the item listed in cell D2.
That total is then subtracted from the Initial Inventory in cell E2, returning
the Current Inventory of the item shown in cell D2.
¾ Solution:
Use the IF, ISERROR, and FIND functions in the following formula:
=IF(ISERROR(FIND("D",B2)),A2,80%*A2)
Explanation:
The FIND function returns the position (character number) of the
character "D" within the text stored in cell B2. If that character does not
appear in cell B2, it returns the #VALUE! error.
The ISERROR function determines whether or not the result of the FIND
function is an error and returns TRUE/FALSE accordingly.
If TRUE is returned (the letter "D" does not appear in the category name in
cell B2), the IF function returns the full price in cell A2.
Otherwise (the letter "D" appears in the category name in cell B2), it
returns 80% of that price (20% discount).
Thus, it returns the appropriate sales price for the full price in cell A2,
based on the category name in cell B2.
¾ Solution:
Use the SUM, ISNUMBER, FIND, MID, ROW, INDIRECT, and LEN
functions as shown in the following Array Formula:
{=SUM(--
ISNUMBER(FIND(MID(B2,ROW(INDIRECT("1:"&LEN(B2))),1),A2)))/LEN(B
2)}
) To apply Array formula:
Select the cell, press <F2> and simultaneously press
<Ctrl+Shift+Enter>.
Explanation:
The ROW and INDIRECT functions are used to create an Array of all the
numbers between 1 and the number representing the length of the string
in cell B2 (calculated by the LEN function).
The MID function uses that Array to create a new Array consisting of all
the characters in cell B2.
The FIND function returns an Array containing the relative positions of
each character extracted by the MID function within the string in cell A2.
If the character is not found within that string, the function returns an
error.
The ISNUMBER returns an Array consisting of a "1" (TRUE) for every
value in that Array that is a number (i.e. represents a character found
within A2), and a "0" (FALSE) for every value that is not a number.
The SUM function adds the values in that Array; thus returning a count of
the characters in B2 that also appear within cell A2.
Finally, that count is divided by the length of cell B2 (calculated by the
LEN function), returning the percentage of characters in cell B2 that also
appear within cell A2.
¾ Solution:
Use the MAX and SUM functions in the following formula:
=MAX(0,$B$1-SUM($A$4:A4))
Explanation:
The SUM function adds all the values in the range $A$4:A4, which
includes all the cells in column A between the first cell ($A$4) and the
cell in the current row.
Thus, it calculates a running total of all the Purchases up to the current
row.
That total is then subtracted from the Credit Limit in cell B1.
The result represents the remaining credit after the purchase listed in the
current row.
The MAX function returns the largest number in a data set that consists of
zero (the first argument of the function) and the remaining credit
calculated above (the second argument of the function).
Thus, it returns the remaining credit only until the credit limit is
exceeded.
Once the credit limit is exceeded (the calculated remaining credit is
smaller than 0), zero is returned.
¾ Solution:
Use the SUM, YEAR, and MONTH functions in the following Array
formula:
{=SUM((YEAR($B$2:$B$6)>C2)*12*$A$2:$A$6+(YEAR($B$2:$B$6)=C2)*
MONTH($B$2:$B$6)*$A$2:$A$6)}
Explanation:
The YEAR function returns the year number of each date in cells B2:B6.
¾ Solution:
Use the INDEX, MATCH, MIN, and IF functions in the following Array
formula:
{=INDEX($B$2:$B$10,MATCH(MIN(IF(((B2-
$B$2:$B$10)>0)*(A2=$A$2:$A$10),(B2-$B$2:$B$10))),B2-
$B$2:$B$10,0))}
Enter the formula in cell C2, and drag down the column.
If a previous payment date does not exist for a particular client, the date
of the current pay date will be displayed in both columns.
Explanation:
The following expression returns an Array of the differences between the
date in cell B2 and each date in cells B2:B10:
B2-$B$2:$B$10
For each date in cells B2:B10 for which that difference is greater than 0
(eliminating the difference between the date in cell B2 and itself), and for
which the corresponding ID (column A) equals the one in cell A2, the IF
function returns the difference calculated above.
Thus, it returns an Array of the differences between the date in cell B2
and each of the pay dates corresponding to the same client ID (cell A2).
The MIN function returns the smallest difference in that Array, which is
the difference between the date in cell B2 and the date of the previous
payment made by the client in cell A2.
The MATCH function returns the position of that difference within the
Array of differences calculated above (by the expression: B2-B2:B10).
The INDEX function returns the date stored in the corresponding position
in column B.
Thus, it returns the date of the previous payment made by the client in
cell A2.
¾ Solution 1:
Use the IF and RANDBETWEEN functions as shown in the following
formula in cell B2:
=IF(A2,RANDBETWEEN(2,12),B2)
Thus, NOW() will automatically recalculate only when the corresponding
value in column A is TRUE.
To stop the result from changing, alter the value in column A to FALSE,
and the last value calculated will remain unchanged upon recalculation.
¾ Solution 2:
To allow iteration calculations:
Select Tools → Options, check the Iteration box, and press OK.
In column A, next to your original formula, enter either TRUE to enable
automatic recalculation or FALSE to disable it.
In place of your original formula in B3 (=NOW()), use the IF and NOW
functions as shown in the following formula:
=IF(A3,NOW(),B3)
¾ Solution:
Use the COUNTIF and COUNTA functions in the following formula, and
then apply percentage formatting to the cells:
=COUNTIF($A$2:$A$9,B2)/COUNTA($A$2:$A$9)
Explanation:
The COUNTIF function returns the number of strings in List1 (cells
A2:A9) that are identical to the string stored in cell B2.
The result is then divided by the total number of strings in List1, as
calculated by the COUNTA function (returns the number of non-blank
cells in cells A2:A9).
Thus, the formula calculates the percentage of strings in List1 that are
identical to the one in cell B2.
¾ Solution:
Use the ABS and MIN functions in the following formula:
=ABS(MIN($A$2:$A$8)-A2)
Explanation:
The MIN function returns the minimum value in List1 (cells A2:A8).
The number stored in cell A2 is then subtracted from the minimum,
returning the difference between them.
The ABS function returns the absolute value of the result, which is the
absolute difference between the number in cell A2 and the minimum
value in the list.
Determining Divisibility
¾ Problem:
Determining whether each of the numbers listed in column A is divisible
by the corresponding number in column B.
¾ Solution:
Use the IF and MOD functions in the following formula:
=IF(MOD(A2,B2)=0,"Divisible","Non-Divisible")
Explanation:
The MOD function divides the number stored in cell A2 by the
corresponding number in cell B2 and returns the remainder.
If the remainder equals 0, the IF function returns the text "Divisible".
Otherwise, it returns "Non-Divisible".
¾ Solution:
Use the INDEX, OFFSET, and MATCH functions in the following formula:
=INDEX(OFFSET($A$3:$D$6,1,1,3,3)*OFFSET($F$3:$I$6,1,1,3,3),
MATCH(B9,$F$3:$F$6,0)-1,MATCH(A9,$A$3:$D$3,0)-1)
Explanation:
The first OFFSET function in the above formula offsets the reference of the
first cell in Matrix1 (cell A3) by 1 column and 1 row and returns an Array
of the values included in a range that starts at that offset reference (cell
B4) and spreads over 3 rows and 3 columns (cells B4:D6).
Thus, it returns an Array consisting of all the values in Matrix1 (without
the index row and column).
Similarly, the second OFFSET function returns an Array consisting of all
the values in Matrix2 (without the index row and column).
The two Arrays returned by the OFFSET functions are then multiplied,
creating an Array of the products of each pair of corresponding values in
Matrix1 and Matrix2. The structure of that Array is identical to the
structure of Matrix1 and Matrix2.
The first MATCH function returns the position (row number) of the value
stored in cell B9 (row index value) within cells F3:F6 (the index column
of Matrix2).
The second MATCH function returns the position (column number) of the
value stored in cell A9 (column index value) within cells A3:D3 (the
index row of Matrix1).
The two numbers returned by the MATCH functions represent the
position (row and column) of the corresponding values in Matrix1 and
Matrix2 for which the product should be returned.
Finally, the INDEX function returns the value stored in that position
within the Array of products created above.
Thus, it returns the product of the corresponding values from each matrix
that are stored in the position indicated by the pair of index values in cells
A9:B9.
¾ Solution 1:
Use the INT function as shown in the following formula:
=INT(A2)+((A2-INT(A2))*4)/10
¾ Solution 2:
Use the DOLLARFR function as shown in the following formula:
=DOLLARFR(A2,4)
Explanation:
) INT Formula:
The INT function in the following expression rounds down the
decimal fraction in cell A2 to the nearest integer.
((A2-INT(A2))*4)
The number returned by the INT function (the integer part of the
fraction in cell A2) is then subtracted from the number in cell A2 and
the result (the non-integer part of the number in cell A2) is multiplied
by 4 (the fraction to which the number in cell A2 should be
converted).
The result of the above expression is divided by 10 (the fraction from
which the number in cell A2 should be converted) and added with
the number returned by the INT function (the integer part of cell A2).
Thus, the decimal fraction in cell A2 is converted to fractions of four,
where each quarter is the equivalent of one decimal unit (tenth).
) DOLLARFR Formula:
The DOLLARFR function converts the decimal number in cell A2 to a
fraction of 4.
¾ Solution:
Step1: Define a name for the repeated part of the formula:
Select a cell → Insert → Name → Define → type the name "value" in
the Names in workbooks text box → and enter the following formula
in the Refers to box:
=VLOOKUP($C2,$A$2:$B$5,2,FALSE)
Step 2: Enter the following formula in cell D2, and copy it down the
column:
=IF(value>=90,value-10,IF(value<=40,value+10,value))
Explanation:
The VLOOKUP function, defined as "value" in the above formula, looks
up the first column of range A2:B5 (column A) for the serial number
entered in cell C2. It then returns the corresponding value from the
second column (column B).
If that value is larger than or equal to 90, the IF function subtracts 10 from
it, and returns the result.
If the value returned by VLOOKUP function is smaller than or equal to
40, the IF function adds 10 to it and returns the result.
Otherwise, it returns the exact value retrieved by the VLOOKUP function.
Converting Units
¾ Problem:
Column A contains 4 pairs of numbers, which represent kilometers,
degrees Celsius, milligrams, and days.
We want to convert the quantities to their equivalents in miles, degrees
Fahrenheit, kilograms, and seconds respectively.
¾ Solution:
Use the CONVERT function as shown in the following formulas:
To convert kilometers to miles:
=CONVERT(A2,"km","mi")
To convert Celsius to Fahrenheit:
=CONVERT(A6,"C","F")
To convert milligrams to kilograms:
=CONVERT(A10,"mg","kg")
To convert days to seconds:
=CONVERT(A14,"day","sec")
Chapter 10
¾ Solution:
Use the INDEX, MATCH, and LOOKUP functions as shown in the
following formula:
=INDEX(TaxTable,MATCH(C13,Bracket),3)+(INDEX(TaxTable,
MATCH(C13,Bracket)+1,2))*(C13-LOOKUP(C13,Bracket))
Step 1: Find the row number of the highest tax bracket below taxable
income.
Step 2: Find the $ amount of the highest tax bracket below taxable
income.
Step 3: Calculate the difference between taxable income and the highest
tax bracket below taxable income.
Step 4: Calculate the tax for the difference between taxable income and
the highest tax bracket below taxable income.
Step 5: Add the accumulated tax for the highest tax bracket below
taxable income + the tax calculated on the in step 4.
Financial Formulas
Using Financial Functions
¾ Problem:
The range B2:G6 contains some of the following parameters for a number
of different loans (each occupying a separate column):
Principal, interest rate, total number of payments, and monthly payment.
Based on those details, we want to calculate the following:
1. Monthly payment for the loan detailed in column B.
2. Principal payments in the first month, first year, and last year for the
loan detailed in column C.
3. Total number of payments for the loan detailed in column D.
4. Interest rate for the loan detailed in column E.
5. Present value of the loan detailed in column F.
6. First month’s interest payment for the loan detailed in column G.
¾ Solution:
Use the formulas as shown in the screenshot.
¾ Solution:
With interest rate in column A, period (years) in column B, and mortgage
sum in column C, use the PMT function as shown in the following
formula:
=PMT((A2/2+1)^(2/12)-1,12*B2,C2,0,0)
Amortization Tables
Creating an Amortization Schedule
¾ Problem:
Listed in cells C3:C5 are the principal, interest rate, and number of
payments for a loan.
Range B3:B5 contains a list of the Names defined for each of the cells in
cells C3:C5.
We want to create an amortization schedule based on the data in cells
B3:C5.
¾ Solution:
Use the formulas as shown in the screenshot.
¾ Solution:
Use the formulas as shown in the screenshot.
¾ Solution:
Use the formulas as shown in the screenshot.
Appendix
List of Functions
ABS
Returns the absolute value of a number.
Function syntax: number
Appears in topic: (page number) 109, 174, 293, 419
ADDRESS
Creates a cell address as text, given specified row and
column numbers.
Function syntax:
row_num,column_num,abs_num,a1,sheet_text
Appears in topic: (page number) 66, 160, 328
AND
Returns TRUE if all its arguments are TRUE; returns FALSE
if one or more arguments is FALSE.
Function syntax: logical1,logical2, ...
Appears in topic: (page number) 63, 73, 221, 222, 223,
224, 229
AVERAGE
Calculates the average arithmetic mean of the values in the
list of arguments.
Function syntax: value1,value2,...
Appears in topic: (page number) 227, 230, 246, 363, 364,
365, 366, 368, 371, 372, 374, 377, 378, 380
CEILING
Returns number rounded up, away from zero, to the nearest
multiple of significance.
Function syntax: number,significance
Appears in topic: (page number) 121, 95, 394
CELL
Returns information about the formatting, location, or
contents of the upper-left cell in a reference.
Function syntax: info_type,reference
Appears in topic: (page number) 380
CHAR
Returns the character specified by a number.
Function syntax: number
Appears in topic: (page number) 56, 64, 186
CHOOSE
Uses index_num to return a value from the list of value
arguments.
Function syntax: index_num,value1,value2,...
Appears in topic: (page number) 94, 98, 140, 216, 401
CODE
Returns a numeric code for the first character in a text
string.
Function syntax: text
Appears in topic: (page number) 56, 64
COLUMN
Returns the column number of the given reference.
Function syntax: reference
Appears in topic: (page number) 66, 166, 177, 206, 207,
208, 261, 285, 308, 328, 355, 356, 357, 380
CONCATENATE
Joins several text strings into one text string.
Function syntax: text1,text2,...
Appears in topic: (page number) 35
CONVERT
Converts a number from one measurement system to
another.
Function syntax: number,from_unit,to_unit
Appears in topic: (page number) 426
COUNT
Counts the number of cells that contain numbers and
numbers within the list of arguments.
Function syntax: value1,value2, ...
Appears in topic: (page number) 123, 242, 251, 292, 366,
376
COUNTA
Counts the number of cells that are not empty and the
values within the list of arguments.
Function syntax: value1,value2, ...
Appears in topic: (page number) 178, 242, 251, 252, 326,
335, 348, 399, 406, 418
COUNTBLANK
Counts empty cells in a specified range of cells.
Function syntax: range
Appears in topic: (page number) 40, 242
COUNTIF
Counts the number of cells within a range that meet the
given criteria.
Function syntax: range,criteria
DATE
Returns the serial number that represents a particular date.
Function syntax: year,month,day
Appears in topic: (page number) 72, 74, 75, 81, 84, 85, 89,
90, 92, 99, 127, 154, 257
DATEDIF
Calculates the number of days, months, or years between
two dates.
Function syntax: start_date,end_date,unit
Appears in topic: (page number) 73
DATEVALUE
Returns the serial number of the date represented by
date_text
Function syntax: date_text
Appears in topic: (page number) 72
DAY
Returns the day of a date, represented by a serial number.
Function syntax: serial_number
Appears in topic: (page number) 73, 89, 92, 99, 154
DOLLARDE
Converts a dollar price expressed as a fraction into a dollar
price expressed as a decimal number.
Function syntax: fractional_dollar,fraction
Appears in topic: (page number) 115, 422
EOMONTH
Returns the serial number for the last day of the month that
is the indicated number of months before or after
start_date.
Function syntax: start_date,months
Appears in topic: (page number) 75, 154
EXACT
Compares two text strings and returns TRUE if they are
exactly the same, FALSE otherwise.
Function syntax: text1,text2
Appears in topic: (page number) 59, 186
FIND
FIND finds one text string (find_text) within another text
string (within_text), and returns the number of the starting
position of find_text, from the first character of within_text.
Function syntax: find_text,within_text,start_num
Appears in topic: (page number) 47, 48, 49, 50, 53, 54, 55,
61, 65, 113, 128, 299, 396, 409, 410
FLOOR
Rounds number down, toward zero, to the nearest multiple
of significance.
Function syntax: number,significance
Appears in topic: (page number) 119, 120, 394
FREQUENCY
Calculates how often values occur within a range of values,
and then returns a vertical array of numbers.
Function syntax: data_array,bins_array
Appears in topic: (page number) 244
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.
Function syntax:
lookup_value,table_array,row_index_num,range_lookup
Appears in topic: (page number) 177
HOUR
Returns the hour of a time value.
Function syntax: serial_number
Appears in topic: (page number) 114, 120
IF
Returns one value if a condition you specify evaluates to
TRUE and another value if it evaluates to FALSE.
Function syntax: logical_test,value_if_true,value_if_false
Appears in topic: (page number) 33, 35, 37, 39, 40, 51, 55,
58, 59, 63, 66, 67, 68, 79, 80, 100, 102, 109, 111, 125,
140, 149, 151, 161, 168, 174, 175, 177, 180, 189, 190,
204, 206, 207, 216, 218, 221, 224, 225, 226, 227, 229,
230, 234, 237, 238, 244, 247, 250, 258, 268, 277, 292,
299, 302, 333, 340, 342, 344, 345, 347, 348, 351, 365,
368, 371, 372, 374, 377, 378, 380, 395, 409, 414, 416,
420, 434, 435, 436
INDEX
Returns the value of a specified cell or array of cells within
array.
Function syntax: array,row_num,column_num
Appears in topic: (page number) 132, 170, 170, 172, 173,
174, 177, 179, 183, 184, 186, 189, 193, 194, 195, 196,
198, 199, 200, 201, 203, 206, 207, 208, 210, 320, 324,
338, 340, 342, 344, 345, 356, 357, 405, 406, 414, 421,
430
INDIRECT
Returns the reference specified by a text string.
Function syntax: ref_text,a1
Appears in topic: (page number) 45, 160, 161, 162, 163,
164, 165, 166, 167, 264, 281, 305, 306, 308, 327, 328,
382, 410
INT
Rounds a number down to the nearest integer.
Function syntax: number
Appears in topic: (page number) 73, 97, 103, 131, 275,
352, 404, 422
IPMT
Returns the interest payment for a given period for an
investment based on periodic, constant payments and a
constant interest rate.
Function syntax: rate,per,nper,pv,fv,type
Appears in topic: (page number) 432, 434
ISBLANK
Returns TRUE if Value refers to an empty cell.
Function syntax: value
Appears in topic: (page number) 39, 40, 41, 231
ISERROR
Returns TRUE if Value refers to any error value #N/A,
#VALUE!, #REF!, #DIV/0!, #NUM!, #NAME?, or #NULL!.
Function syntax: value
Appears in topic: (page number) 58, 227, 234, 409
ISNA
Returns TRUE if Value refers to the #N/A (value not available)
error value.
ISNUMBER
Returns TRUE if Value refers to a number.
Function syntax: value
Appears in topic: (page number) 41, 45, 55, 60, 61, 224,
230, 231, 299, 302, 410
ISTEXT
Returns TRUE if Value refers to text.
Function syntax: value
Appears in topic: (page number) 27, 41, 250
LARGE
Returns the k-th largest value in a data set.
Function syntax: array,k
Appears in topic: (page number) 170, 181, 327, 332, 336,
374, 385, 387
LCM
Returns the least common multiple of integers.
Function syntax: number1,number2, ..
Appears in topic: (page number) 383
LEFT
LEFT returns the first character or characters in a text
string, based on the number of characters you specify.
Function syntax: text,num_chars
Appears in topic: (page number) 45, 47, 48, 49, 50, 53, 54,
55, 60, 63, 65, 72, 100, 102, 113, 128, 252, 299, 383,
386, 396
LEN
LEN returns the number of characters in a text string.
Function syntax: text
Appears in topic: (page number) 28, 48, 51, 61, 65, 113,
248, 255, 410
LOOKUP
Returns a value from an array.
Returns a value either from a one-row or one-column range.
Function syntax: lookup_value,array
Function syntax: lookup_value,lookup_vector,result_vector
Appears in topic: (page number) 168, 430
LOWER
Converts all uppercase letters in a text string to lowercase.
Function syntax: text
Appears in topic: (page number) 59
MATCH
Returns the relative position of an item in an array that
matches a specified value in a specified order.
Function syntax: lookup_value,lookup_array,match_type
Appears in topic: (page number) 98, 132, 170, 172, 173,
179, 183, 184, 186, 194, 195, 196, 198, 199, 200, 201,
203, 206, 210, 211, 281, 319, 338, 356, 414, 421, 430
MAX
Returns the largest value in a set of values.
Function syntax: number1,number2,...
Appears in topic: (page number) 45, 66, 68, 83, 84, 136,
140, 147, 172, 177, 180, 184, 190, 203, 208, 210, 383,
386, 388, 411
MID
MID returns a specific number of characters from a text
string, starting at the position you specify, based on the
number of characters you specify.
Function syntax: text,start_num,num_chars
Appears in topic: (page number) 34, 45, 47, 50, 53, 54, 63,
64, 72, 113, 128, 396, 410
MIN
Returns the smallest number in a set of values.
Function syntax: number1,number2, ...
Appears in topic: (page number) 79, 84, 92, 147, 174, 184,
206, 207, 280, 376, 382, 383, 414, 419
MINUTE
Returns the minutes of a time value.
Function syntax: serial_number
Appears in topic: (page number) 114, 120
MMULT
Returns the matrix product of two arrays.
Function syntax: array1,array2
Appears in topic: (page number) 268, 283, 285
MOD
Returns the remainder after number is divided by divisor.
Function syntax: number,divisor
Appears in topic: (page number) 80, 33, 36, 95, 100, 130,
131, 161, 190, 222, 233, 261, 263, 275, 352, 377, 378,
380, 395, 420
MODE
Returns the most frequently occurring, or repetitive, value in
an array or range of data.
MONTH
Returns the month of a date represented by a serial number.
Function syntax: serial_number
Appears in topic: (page number) 95, 72, 73, 92, 97, 98, 99,
231, 258, 273, 322, 413
NETWORKDAYS
Returns the number of whole working days between
start_date and end_date.
Function syntax: start_date,end_date,holidays
Appears in topic: (page number) 77, 130
NOW
Returns the serial number of the current date and time.
Appears in topic: (page number) 125, 416
NPER
Returns the number of periods for an investment based on
periodic, constant payments and a constant interest rate.
Function syntax: rate, pmt, pv, fv, type
Appears in topic: (page number) 432
OFFSET
Returns a reference to a range that is a specified number of
rows and columns from a cell or range of cells.
Function syntax: reference,rows,cols,height,width
Appears in topic: (page number) 152, 178, 192, 211, 252,
280, 292, 319, 324, 326, 328, 335, 352, 355, 399, 421
OR
Returns TRUE if any argument is TRUE; returns FALSE if all
arguments are FALSE.
PMT
Calculates the payment for a loan based on constant
payments and a constant interest rate.
Function syntax: rate,nper,pv,fv,type
Appears in topic: (page number) 432, 433, 434, 435
PPMT
Returns the payment on the principal for a given period for an
investment based on periodic, constant payments and a
constant interest rate.
Function syntax: rate,per,nper,pv,fv,type
Appears in topic: (page number) 432, 434
PV
Returns the present value of an investment.
Function syntax: rate,nper,pmt,fv,type
Appears in topic: (page number) 432
RAND
Returns an evenly distributed random number greater than
or equal to 0 and less than 1. A new random number is
returned every time the worksheet is calculated.
Appears in topic: (page number) 36, 336, 402, 404, 406
RANDBETWEEN
Returns a random number between the numbers you specify.
A new random number is returned every time the worksheet
is calculated.
Function syntax: bottom,top
Appears in topic: (page number) 405, 416
RANK
Returns the rank of a number in a list of numbers.
Function syntax: number,ref,order
Appears in topic: (page number) 398, 399, 401, 402
RATE
Returns the interest rate per period of an annuity.
Function syntax: nper,pmt,pv,fv,type,guess
Appears in topic: (page number) 432
REPT
Repeats text a given number of times.
Function syntax: text,number_times
Appears in topic: (page number) 177
RIGHT
RIGHT returns the last character or characters in a text
string, based on the number of characters you specify.
Function syntax: text,num_chars
Appears in topic: (page number) 47, 48, 51, 60, 65, 72,
102, 273
ROUND
Rounds a number to a specified number of digits.
Function syntax: number,num_digits
Appears in topic: (page number) 122, 235, 296, 390, 391,
393, 395, 396, 406
ROUNDDOWN
Rounds a number down, toward zero.
Function syntax: number,num_digits
Appears in topic: (page number) 119
ROUNDUP
Rounds a number up, away from 0 zero.
Function syntax: number,num_digits
Appears in topic: (page number) 78, 322, 397
ROW
Returns the row number of a reference.
Function syntax: reference
Appears in topic: (page number) 33, 36, 45, 66, 67, 68,
140, 161, 174, 189, 190, 193, 278, 280, 281, 306, 327,
328, 332, 335, 336, 340, 342, 344, 345, 352, 355, 357,
377, 378, 391, 402, 410, 434
SEARCH
Returns the number of the character at which a specific
character or text string is first found, beginning with
start_num.
Function syntax: find_text,within_text,start_num
Appears in topic: (page number) 61
SMALL
Returns the k-th smallest value in a data set.
Function syntax: array,k
Appears in topic: (page number) 67, 56, 64, 181, 189, 332,
340, 342, 344, 345, 356, 385
SQRT
Returns a positive square root.
Function syntax: number
Appears in topic: (page number) 36
SUBSTITUTE
Substitutes new_text for old_text in a text string.
Function syntax: text,old_text,new_text,instance_num
Appears in topic: (page number) 43, 45, 49, 51, 128, 248,
255, 256, 300, 301
SUBTOTAL
Returns a subtotal in a list or database.
Function syntax: function_num,ref1,ref2,...
Appears in topic: (page number) 187, 280, 294
SUM
Adds all the numbers in a range of cells.
Function syntax: number1,number2, ...
Appears in topic: (page number) 37, 66, 106, 106, 107,
135, 140, 143, 144, 156, 225, 244, 247, 252, 258, 264,
268, 277, 285, 290, 291, 292, 293, 294, 296, 299, 300,
301, 302, 305, 308, 314, 317, 319, 322, 324, 326, 327,
328, 366, 376, 391, 410, 411, 413, 434, 435, 436
SUMIF
Adds the cells specified by a given criteria.
Function syntax: range,criteria,sum_range
Appears in topic: (page number) 250, 298, 302, 304, 306,
310, 311, 312, 315, 320, 323, 371, 407
SUMPRODUCT
Multiplies corresponding components in the given arrays, and
returns the sum of those products.
Function syntax: array1,array2,array3, ...
Appears in topic: (page number) 152, 208, 231, 244, 248,
256, 258, 261, 263, 265, 269, 271, 272, 273, 275, 276,
280, 283, 286, 295, 304, 306, 313, 314, 315, 348, 350
TEXT
Converts a value to text in a specific number format.
Function syntax: value,format_text
Appears in topic: (page number) 30, 31, 32, 35, 43, 94,
115, 132, 139, 165, 383, 386
TIME
Returns the decimal number for a particular time.
Function syntax: hour,minute,second
Appears in topic: (page number) 103, 107, 120, 126, 127,
149, 151
TIMEVALUE
Returns the decimal number of the time represented by a
text string.
Function syntax: time_text
Appears in topic: (page number) 102, 106
TODAY
Returns the serial number of the current date.
Appears in topic: (page number) 72, 75, 80, 99, 156
TRANSPOSE
Returns a vertical range of cells as a horizontal range, or vice
versa.
Function syntax: array
Appears in topic: (page number) 268, 285, 357
TRIM
Removes all spaces from text except for single spaces
between words.
Function syntax: text
Appears in topic: (page number) 49, 43, 235
TRIMMEAN
Returns the mean of the interior of a data set.
Function syntax: array,percent
TRUNC
Truncates a number to an integer by removing the fractional
part of the number.
Function syntax: number,num_digits
Appears in topic: (page number) 139
UPPER
Converts text to uppercase.
Function syntax: text
Appears in topic: (page number) 59
VALUE
Converts a text string that represents a number to a
number.
Function syntax: text
Appears in topic: (page number) 44, 51, 235, 256, 299,
300, 301
VLOOKUP
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.
Function syntax:
lookup_value,table_array,col_index_num,range_lookup
Appears in topic: (page number) 34, 118, 163, 167, 201,
204, 234, 235, 237, 238, 336, 402, 424
WEEKDAY
Returns the day of the week corresponding to a date.
Function syntax: serial_number,return_type
Appears in topic: (page number) 74, 81, 90, 147, 372
WEEKNUM
Returns a number that indicates where the week falls
numerically within a year.
Function syntax: serial_num,return_type
Appears in topic: (page number) 87, 88
WORKDAY
Returns a number that represents a date that is the
indicated number of working days before or after a date the
starting date.
Function syntax: start_date,days,holidays
Appears in topic: (page number) 78
YEAR
Returns the year corresponding to a date.
Function syntax: serial_number
Appears in topic: (page number) 72, 73, 92, 97, 99, 413
Index
A Converting
Amortization Tables Decimal Fractions, 422
Amortization Tables, Creating Schedule, Units, 426
434 Counting, 241
Amortization Tables, Grace, 435 Above Average, 246
Amortization Tables, Random Loan Appear Only Once, 247
Payments, 436 Below Average, 246
Array Formula Between Limits, 268
Understanding Arrays, 12 Combined Text, 252
Using Arrays in Formulas, 12 Complex, 277
Averaging Date & Time, 275
Annual Growth, 363 Date Values, 257, 258
Criteria, 365, 366, 368, 369, 371, 376 Dynamic Range, 252
Dynamic Range, 374 Every N Values, 261
Growth, 364 Excel Files, 273
Nth numbers, 377, 378, 380 Filtered List, 280
Sales, 372 Grid, 286
Item Sold, 276
C Lists, 266
Calculating Matrix, 285
Absolute Difference, 419 Multiple Worksheets, 264
Annual Payment, 413 One Criterion, 244
Automatic Recalculation, 416 Players, 271
Payment, 414 Progressively Increment, 278
Percentage, 418 Rows, 263, 265
Proportion, 410 Student Questionnaire, 281, 283
Remaining Credit, 411 Students, 272
Sale Price, 409 Substrings Contain Numbers, 256
Commissions Substrings, 248, 255
Sales Rank, 401 Text, 250, 251
Time Values, 260
L R
List, 331 Random, 402, 404, 405, 406
Creating by Criteria, 338 Avoiding Duplicate, 402
Duplicate, 348, 351 Ranking, 398
I would appreciate it if you could find a few moments and share with us your
thoughts, comments, suggestions, ideas, tips, areas to cover, helpful solutions that
other Excel users might need, and how we can improve and make this book better.
Author
jrubin@exceltip.com
www.exceltip.com
F1 Get the Most out of Excel! The Ultimate Excel Help Tip Guide (print &
e-Book)
Financial Statements.xls (print & e-Book)
8 No matter which Excel version you use Excel 97, 2000, 2002 or 2003, this easy
8 You can add your own notes, reference tips and examples to any page,
personalizing it to meet your exact needs!
Author:
Joseph Rubin, CPA, has written the very successful books:
8 Financial Statements.xls
8 Mr Excel on Excel
He is the principal of the leading Excel Web site www.exceltip.com, and has more
than 25 years of financial experience in the accounting industry.
This book is for: Accountants, CPA'S, Controllers, Developers, Consultants and Instructors. Bonus CD-Rom Included
Bonus CD-Rom Includes:
8 Complete searchable eBook – easy to browse and print.
8 Sample Financial Statements in Excel workbook file.
8 Excel workbook files contain all data and formulas covered in the book.
8 Additional Bonus: A number of free Add-Ins.
Author:
Joseph Rubin, CPA, principal of www.exceltip.com is the author of the very successful book
F1 Get the Most out of Excel! The Ultimate Excel Tip Help Guide.
Joseph Rubin has more than 25 years of financial experience in the accounting industry.