Excel Notes Part 2
Excel Notes Part 2
Summary
The Excel OFFSET function returns a reference to a range constructed in parts: a starting point, a
row and column offset, and a final height and width in rows and columns. OFFSET is handy in
formulas that dynamically average or sum "last n values".
Purpose
Create a reference offset from given starting point
Return value
A cell reference.
Syntax
=OFFSET (reference, rows, cols, [height], [width])
Arguments
reference - The starting point, supplied as a cell reference or range.
rows - The number of rows to offset below the starting reference.
cols - The number of columns to offset to the right of the starting reference.
height - [optional] The height in rows of the returned reference.
width - [optional] The width in columns of the returned reference.
Usage notes
OFFSET returns a reference to a range that is offset from a starting point in a worksheet. The
starting point can be one cell or a range of cells, and the offset is supplied as rows or columns
"offset" from the starting point. The height and width arguments are optional and determine
the size of the reference that is created.
OFFSET can be used to build a dynamic named range for charts or pivot tables, to make sure that
source data is always up to date.
Generic formula
=SUM(OFFSET(first,0,(COLUMN()-COLUMN(current))*n, 1,n))
Explanation
To write a formula that will sum "the next 3" cells each time it's copied, you can use the
OFFSET function. In the example shown, the formula in O5 is:
=SUM(OFFSET($B5,0,(COLUMN()-COLUMN($O$5))*3, 1,3))
Note: the point of this formula is to eliminate the manual task of entering
ranges manually with a single global formula, at the cost of a more complex
formula.
How this formula works
At the core, the OFFSET function delivers a range of 3 cells to SUM, which returns a summed
result.
For reference we use the first cell in the data range, B5, entered as a mixed
reference (column locked, row relative).
For rows, we use 0, since we don't need to change rows.
For cols, we use the expression:
(COLUMN()-COLUMN($O$5))*3
This part of the formula figures out how many columns from the starting reference to offset. In
O5, the offset is zero, in P5, the offset is 3, and so on.
Finally, height is input as 1 and width is input as 3, since in this case we always want a 1 x
3 range of cells.
Note: change 3 to the multiplier you need, shown as "n" in the generic form
of the formula above.
HLOOKUP function
Description
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. Use HLOOKUP when your
comparison values are located in a row across the top of a table of data, and you want to look
down a specified number of rows. Use VLOOKUP when your comparison values are located in a
column to the left of the data you want to find.
The H in HLOOKUP stands for "Horizontal."off
Syntax
HLOOKUP(lookup_value, table_array, row_index_num, [range_lookup])
The HLOOKUP function syntax has the following arguments:
Lookup_value Required. The value to be found in the first row of the table.
Lookup_value can be a value, a reference, or a text string.
Table_array Required. A table of information in which data is looked up. Use a
reference to a range or a range name.
The values in the first row of table_array can be text, numbers, or logical values.
If range_lookup is TRUE, the values in the first row of table_array must be placed
in ascending order: ...-2, -1, 0, 1, 2,... , A-Z, FALSE, TRUE; otherwise,
HLOOKUP may not give the correct value. If range_lookup is FALSE,
table_array does not need to be sorted.
Uppercase and lowercase text are equivalent.
Sort the values in ascending order, left to right. For more information, see Sort
data in a range or table.
Row_index_num Required. The row number in table_array from which the matching
value will be returned. A row_index_num of 1 returns the first row value in table_array, a
row_index_num of 2 returns the second row value in table_array, and so on. If
row_index_num is less than 1, HLOOKUP returns the #VALUE! error value; if
row_index_num is greater than the number of rows on table_array, HLOOKUP returns
the #REF! error value.
Range_lookup Optional. A logical value that specifies whether you want HLOOKUP
to find an exact match or an approximate match. If TRUE or omitted, an approximate
match is returned. In other words, if an exact match is not found, the next largest value
that is less than lookup_value is returned. If FALSE, HLOOKUP will find an exact
match. If one is not found, the error value #N/A is returned.
Remark
If HLOOKUP can't find lookup_value, and range_lookup is TRUE, it uses the largest
value that is less than lookup_value.
If lookup_value is smaller than the smallest value in the first row of table_array,
HLOOKUP returns the #N/A error value.
If range_lookup is FALSE and lookup_value is text, you can use the wildcard characters,
question mark (?) and asterisk (*), in lookup_value. A question mark matches any single
character; an asterisk matches any sequence of characters. If you want to find an actual
question mark or asterisk, type a tilde (~) before the character.
Example
Copy the example data in the following table, and paste it in cell A1 of a new Excel worksheet.
For formulas to show results, select them, press F2, and then press Enter. If you need to, you can
adjust the column widths to see all the data.
Axles Bearings Bolts
4 4 9
5 7 10
6 8 11
=HLOOKUP("Axles", A1:C4, 2, Looks up "Axles" in row 1, and returns the value from row 2 that's 4
TRUE) in the same column (column A).
=HLOOKUP("Bearings", A1:C4, 3, Looks up "Bearings" in row 1, and returns the value from row 3 7
FALSE) that's in the same column (column B).
=HLOOKUP("B", A1:C4, 3, Looks up "B" in row 1, and returns the value from row 3 that's in 5
TRUE) the same column. Because an exact match for "B" is not found, the
largest value in row 1 that is less than "B" is used: "Axles," in
column A.
=HLOOKUP("Bolts", A1:C4, 4) Looks up "Bolts" in row 1, and returns the value from row 4 that's 11
in the same column (column C).
=HLOOKUP(3, Looks up the number 3 in the three-row array constant, and returns c
{1,2,3;"a","b","c";"d","e","f"}, 2, the value from row 2 in the same (in this case, third) column. There
TRUE) are three rows of values in the array constant, each row separated
by a semicolon (;). Because "c" is found in row 2 and in the same
column as 3, "c" is returned.
VLOOKUP function
Use VLOOKUP when you need to find things in a table or a range by row. For example, look up
a price of an automotive part by the part number, or find an employee name based on their
employee ID.
In its simplest form, the VLOOKUP function says:
=VLOOKUP(What you want to look up, where you want to look for it, the column number in
the range containing the value to return, return an Approximate or Exact match – indicated as
1/TRUE, or 0/FALSE).
Play Video
Tips:
The secret to VLOOKUP is to organize your data so that the value you look up (Fruit) is
to the left of the return value (Amount) you want to find.
If you're a Microsoft Copilot subscriber Copilot can make it even easier to insert and use
VLookup or XLookup functions. See Copilot makes lookups in Excel easy.
Technical details
How to get started
There are four pieces of information that you will need in order to build the VLOOKUP syntax:
1. The value you want to look up, also called the lookup value.
2. The range where the lookup value is located. Remember that the lookup value should
always be in the first column in the range for VLOOKUP to work correctly. For example,
if your lookup value is in cell C2 then your range should start with C.
3. The column number in the range that contains the return value. For example, if you
specify B2:D11 as the range, you should count B as the first column, C as the second, and
so on.
4. Optionally, you can specify TRUE if you want an approximate match or FALSE if you
want an exact match of the return value. If you don't specify anything, the default value
will always be TRUE or approximate match.
Now put all of the above together as follows:
=VLOOKUP(lookup value, range containing the lookup value, the column number in the range
containing the return value, Approximate match (TRUE) or Exact match (FALSE)).
Examples
Here are a few examples of VLOOKUP:
Example 1
Example 2
Example 3
Example 4
Example 5
INDEX function
Applies To
The INDEX function returns a value or the reference to a value from within a table or range.
Play Video
There are two ways to use the INDEX function:
If you want to return the value of a specified cell or array of cells, see Array form.
If you want to return a reference to specified cells, see Reference form.
Array form
Description
Returns the value of an element in a table or an array, selected by the row and column number
indexes.
Use the array form if the first argument to INDEX is an array constant.
Syntax
INDEX(array, row_num, [column_num])
The array form of the INDEX function has the following arguments:
array Required. A range of cells or an array constant.
If array contains only one row or column, the corresponding row_num or
column_num argument is optional.
If array has more than one row and more than one column, and only row_num or
column_num is used, INDEX returns an array of the entire row or column in
array.
row_num Required, unless column_num is present. Selects the row in array from
which to return a value. If row_num is omitted, column_num is required.
column_num Optional. Selects the column in array from which to return a value. If
column_num is omitted, row_num is required.
Remarks
If both the row_num and column_num arguments are used, INDEX returns the value in
the cell at the intersection of row_num and column_num.
row_num and column_num must point to a cell within array; otherwise, INDEX returns a
#REF! error.
If you set row_num or column_num to 0 (zero), INDEX returns the array of values for
the entire column or row, respectively. To use values returned as an array, enter the
INDEX function as an array formula.
Examples
Example 1
These examples use the INDEX function to find the value in the intersecting cell where a row
and a column meet.
Copy the example data in the following table, and paste it in cell A1 of a new Excel worksheet.
For formulas to show results, select them, press F2, and then press Enter.
Data Data
Apples Lemons
Bananas Pears
=INDEX(A2:B3,2,2) Value at the intersection of the second row and second column in the range Pears
A2:B3.
Data Data
=INDEX(A2:B3,2,1) Value at the intersection of the second row and first column in the range A2:B3. Bananas
Example 2
This example uses the INDEX function in an array formula to find the values in two cells
specified in a 2x2 array.
=INDEX({1,2;3,4},0,2 Value found in the first row, second column in the array. The array contains 1 2
) and 2 in the first row and 3 and 4 in the second row.
Value found in the second row, second column in the array (same array as 4
above).
Reference form
Description
Returns the reference of the cell at the intersection of a particular row and column. If the
reference is made up of non-adjacent selections, you can pick the selection to look in.
Syntax
INDEX(reference, row_num, [column_num], [area_num])
The reference form of the INDEX function has the following arguments:
reference Required. A reference to one or more cell ranges.
If you are entering a non-adjacent range for the reference, enclose reference in
parentheses.
If each area in reference contains only one row or column, the row_num or
column_num argument, respectively, is optional. For example, for a single row
reference, use INDEX(reference,,column_num).
row_num Required. The number of the row in reference from which to return a
reference.
column_num Optional. The number of the column in reference from which to return a
reference.
area_num Optional. Selects a range in reference from which to return the intersection
of row_num and column_num. The first area selected or entered is numbered 1, the
second is 2, and so on. If area_num is omitted, INDEX uses area 1. The areas listed here
must all be located on one sheet. If you specify areas that are not on the same sheet as
each other, it will cause a #VALUE! error. If you need to use ranges that are located on
different sheets from each other, it is recommended that you use the array form of the
INDEX function, and use another function to calculate the range that makes up the array.
For example, you could use the CHOOSE function to calculate which range will be used.
For example, if Reference describes the cells (A1:B4,D1:E4,G1:H4), area_num 1 is the range
A1:B4, area_num 2 is the range D1:E4, and area_num 3 is the range G1:H4.
Remarks
After reference and area_num have selected a particular range, row_num and
column_num select a particular cell: row_num 1 is the first row in the range,
column_num 1 is the first column, and so on. The reference returned by INDEX is the
intersection of row_num and column_num.
If you set row_num or column_num to 0 (zero), INDEX returns the reference for the
entire column or row, respectively.
row_num, column_num, and area_num must point to a cell within reference; otherwise,
INDEX returns a #REF! error. If row_num and column_num are omitted, INDEX returns
the area in reference specified by area_num.
The result of the INDEX function is a reference and is interpreted as such by other
formulas. Depending on the formula, the return value of INDEX may be used as a
reference or as a value. For example, the formula CELL("width",INDEX(A1:B2,1,2)) is
equivalent to CELL("width",B1). The CELL function uses the return value of INDEX as
a cell reference. On the other hand, a formula such as 2*INDEX(A1:B2,1,2) translates
the return value of INDEX into the number in cell B1.
Examples
Copy the example data in the following table, and paste it in cell A1 of a new Excel worksheet.
For formulas to show results, select them, press F2, and then press Enter.
Apples $0.69 40
Bananas $0.34 38
Lemons $0.55 15
Oranges $0.25 25
Pears $0.59 40
Almonds $2.80 10
Fruit Price Count
Cashews $3.55 16
Peanuts $1.25 20
Walnuts $1.75 12
=INDEX(A2:C6, 2, 3) The intersection of the second row and third column in the range A2:C6, 38
which is the contents of cell C3.
=INDEX((A1:C6, A8:C11), 2, The intersection of the second row and second column in the second 1.25
2, 2) area of A8:C11, which is the contents of cell B9.
=SUM(INDEX(A1:C11, 0, 3, The sum of the third column in the first area of the range A1:C11, which 216
1)) is the sum of C1:C11.
=SUM(B2:INDEX(A2:C6, 5, The sum of the range starting at B2, and ending at the intersection of the 2.42
2)) fifth row and the second column of the range A2:A6, which is the sum
of B2:B6.
MATCH function
Applies To
The MATCH function searches for a specified item in a range of cells, and then returns the
relative position of that item in the range. For example, if the range A1:A3 contains the values 5,
25, and 38, then the formula =MATCH(25,A1:A3,0) returns the number 2, because 25 is the
second item in the range.
Play Video
Syntax
MATCH(lookup_value, lookup_array, [match_type])
The MATCH function syntax has the following arguments:
lookup_value Required. The value that you want to match in lookup_array. For
example, when you look up someone's number in a telephone book, you are using the
person's name as the lookup value, but the telephone number is the value you want.
The lookup_value argument can be a value (number, text, or logical value) or a cell
reference to a number, text, or logical value.
lookup_array Required. The range of cells being searched.
match_type Optional. The number -1, 0, or 1. The match_type argument specifies how
Excel matches lookup_value with values in lookup_array. The default value for this
argument is 1.
The following table describes how the function finds values based on the setting of
the match_type argument.
Match_typ Behavior
e
1 or omitted MATCH finds the largest value that is less than or equal to lookup_value. The values
in the lookup_array argument must be placed in ascending order, for example: ...-2, -
1, 0, 1, 2, ..., A-Z, FALSE, TRUE.
0 MATCH finds the first value that is exactly equal to lookup_value. The values in
the lookup_array argument can be in any order.
-1 MATCH finds the smallest value that is greater than or equal tolookup_value. The
values in the lookup_array argument must be placed in descending order, for example:
TRUE, FALSE, Z-A, ...2, 1, 0, -1, -2, ..., and so on.
MATCH returns the position of the matched value within lookup_array, not the value
itself. For example, MATCH("b",{"a","b","c"},0) returns 2, which is the relative
position of "b" within the array {"a","b","c"}.
MATCH does not distinguish between uppercase and lowercase letters when matching
text values.
If MATCH is unsuccessful in finding a match, it returns the #N/A error value.
If match_type is 0 and lookup_value is a text string, you can use the wildcard
characters — the question mark (?) and asterisk (*) — in the lookup_value argument. A
question mark matches any single character; an asterisk matches any sequence of
characters. If you want to find an actual question mark or asterisk, type a tilde (~) before
the character.
Example
Copy the example data in the following table, and paste it in cell A1 of a new Excel worksheet.
For formulas to show results, select them, press F2, and then press Enter. If you need to, you can
adjust the column widths to see all the data.
Product Count
Bananas 25
Oranges 38
Apples 40
Pears 41
=MATCH(39,B2:B5,1) Because there is not an exact match, the position of the next 2
lowest value (38) in the range B2:B5 is returned.
=MATCH(40,B2:B5,- Returns an error because the values in the range B2:B5 are not in #N/A
1) descending order.
Argumen
Description Required?
t
“rate” The fixed interest rate on the loan as stated in the Required
lending agreement.
If applicable to the scenario, the rate must be
converted for the units to be consistent (e.g.
monthly, quarterly, semi-annual, annual).
“pv” The present value (PV) of the loan is the value of Required
a series of payments on the current date, i.e. the
principal value on the original issuance date.
“fv” The future value (FV) specifies the value of the Optional
Argumen
Description Required?
t