+ All Categories
Home > Documents > Syntax and Purpose of Functions

Syntax and Purpose of Functions

Date post: 11-Sep-2014
Category:
Upload: ashrrut-kaim
View: 126 times
Download: 1 times
Share this document with a friend
Popular Tags:
65
SYNTAX AND PURPOSE OF FUNCTIONS 1. Mathematical Functions i. ABS: Returns the absolute value of a number. The absolute value of a number is the number without its sign. = ABS(number) Number: (Required) the real number of which you want the absolute value. Eg: ii. INT: Rounds a number down to the nearest integer. =int(number) Number: (Required) the real number you want to round down to an integer. Eg: iii. MOD: Returns the remainder after number is divided by divisor. The result has the same sign as divisor. The MOD function syntax has the following arguments: Number Required. The number for which you want to find the remainder. Divisor Required If divisor is 0, MOD returns the #DIV/0! error value. The MOD function can be expressed in terms of the INT function: MOD(n, d) = n - d*INT(n/d) Formula Description (Result) =MOD(3, 2) Remainder of 3/2 (1) =MOD(-3, 2) Remainder of -3/2. The sign is the same as divisor (1) =MOD(3, - 2) Remainder of 3/-2. The sign is the same as divisor (-1) Formula Description (Result) =ABS(2) Absolute value of 2 (2) =ABS(-2) Absolute value of -2 (2) =ABS(A2) Absolute value of -4 (4) Suppose A2 contains - 4 Formula Description (Result) INT(8.9) Rounds 8.9 down (8) =INT(- 8.9) Rounds -8.9 down (-9) =A2- INT(A2) Returns the decimal part of a positive real number in cell A2 (0.5) Suppose A2 contains 19.5
Transcript
Page 1: Syntax and Purpose of Functions

SYNTAX AND PURPOSE OF FUNCTIONS

1. Mathematical Functions

i. ABS: Returns the absolute value of a number. The absolute value of a number is the number without its sign.

= ABS(number)Number: (Required) the real number of which you want the absolute value.

Eg:

ii. INT: Rounds a number down to the nearest integer. =int(number)

Number: (Required) the real number you want to round down to an integer.

Eg:

iii. MOD: Returns the remainder after number is divided by divisor. The result has the same sign as divisor.

The MOD function syntax has the following arguments:Number Required. The number for which you want to find the remainder. Divisor RequiredIf divisor is 0, MOD returns the #DIV/0! error value.The MOD function can be expressed in terms of the INT function:MOD(n, d) = n - d*INT(n/d)

Formula Description (Result)

=MOD(3, 2) Remainder of 3/2 (1)=MOD(-3, 2)

Remainder of -3/2. The sign is the same as divisor (1)

=MOD(3, -2)

Remainder of 3/-2. The sign is the same as divisor (-1)

=MOD(-3, -2)

Remainder of -3/-2. The sign is the same as divisor (-1)

iv. Power : Returns the result of a number raised to a power.POWER(number, power)

Number Required. The base number. It can be any real number. Power Required. The exponent to which the base number is raised.

The "^" operator can be used instead of POWER to indicate to what power the base number is to be raised, such as in 5^2.

Formula Description (Result)

=ABS(2) Absolute value of 2 (2)

=ABS(-2) Absolute value of -2 (2)

=ABS(A2) Absolute value of -4 (4)Suppose A2 contains - 4

Formula Description (Result)INT(8.9) Rounds 8.9 down (8)=INT(-8.9) Rounds -8.9 down (-9)=A2-INT(A2)

Returns the decimal part of a positive real number in cell A2 (0.5)Suppose A2 contains 19.5

Page 2: Syntax and Purpose of Functions

1234

A BFormula Description (Result)=POWER(5,2) 5 squared (25)=POWER(98.6,3.2)

98.6 raised to the power of 3.2 (2401077)

=POWER(4,5/4) 4 raised to the power of 5/4 (5.656854)

v. Product: The PRODUCT function multiplies all the numbers given as arguments and returns the product. For example, if cells A1 and A2 contain numbers, you can use the formula =PRODUCT(A1, A2) to multiply those two numbers together. You can also perform the same operation by using the multiply (*) mathematical operator; for example, =A1 * A2.The PRODUCT function is useful when you need to multiply many cells together. For example, the formula =PRODUCT(A1:A3, C1:C3) is equivalent to =A1 * A2 * A3 * C1 * C2 * C3.PRODUCT(number1, [number2], ...)

number1 Required. The first number or range that you want to multiply. number2, ... Optional. Additional numbers or ranges that you want to multiply, up to a maximum of

255 arguments.NOTE If an argument is an array or reference, only numbers in the array or reference are multiplied. Empty cells, logical values, and text in the array or reference are ignored.

12345

6

7

8

A B CData51530Formula Description Resu

lt=PRODUCT(A2:A4)

Multiplies the numbers in cells A2 through A4. 2250

=PRODUCT(A2:A4, 2)

Multiplies the numbers in cells A2 through A4, and then multiplies that result by 2.

4500

=A2*A3*A4 Multiplies the numbers in cells A2 through A4 by using mathematical operators instead of the PRODUCT function.

Vi. Round: The ROUND function rounds a number to a specified number of digits. For example, if cell A1 contains 23.7825, and you want to round that value to two decimal places, you can use the following formula:=ROUND(A1, 2)The result of this function is 23.78.ROUND(number, num_digits)The ROUND function syntax has the following arguments:

number Required. The number that you want to round. num_digits Required. The number of digits to which you want to round the number argument.If num_digits is greater than 0 (zero), then number is rounded to the specified number of decimal

places. If num_digits is 0, the number is rounded to the nearest integer. If num_digits is less than 0, the number is rounded to the left of the decimal point. To always round up (away from zero), use the ROUNDUP function. To always round down (toward zero), use the ROUNDDOWN function. To round a number to a specific multiple (for example, to round to the nearest 0.5), use the

MROUND function.

1 A B C

Page 3: Syntax and Purpose of Functions

2

3

4

5

Formula Description Result

=ROUND(2.15, 1)

Rounds 2.15 to one decimal place 2.2

=ROUND(2.149, 1)

Rounds 2.149 to one decimal place 2.1

=ROUND(-1.475, 2)

Rounds -1.475 to two decimal places -1.48

=ROUND(21.5, -1)

Rounds 21.5 to one decimal place to the left of the decimal point

VII. Sign: Determines the sign of a number. Returns 1 if the number is positive, zero (0) if the number is 0, and -1 if the number is negative.

SIGN(number)Number Required. Any real number.

1234

A BFormula Description (Result)=SIGN(10) Sign of a positive number

(1)=SIGN(4-4) Sign of zero (0)=SIGN(-0.00001)

Sign of a negative number (-1)

VII. SQRT: Returns a positive square root.SQRT(number)

The SQRT function syntax has the following arguments: Number Required. The number for which you want the square root. If number is negative, SQRT returns the #NUM! error value.

1234

5

6

A BData-16Formula Description (Result)=SQRT(16) Square root of 16 (4)=SQRT(A2) Square root of the number above. Because the number is negative, an

error is returned (#NUM!)=SQRT(ABS(A2))

Square root of the absolute value of the number above (4)

VIII. Subtotal : Returns a subtotal in a list or database. It is generally easier to create a list with subtotals by using the Subtotal command in the Outline group on the Data tab. Once the subtotal list is created, you can modify it by editing the SUBTOTAL function.

SUBTOTAL(function_num,ref1,[ref2],...])

The SUBTOTAL function syntax has the following arguments:Function_num Required. The number 1 to 11 (includes hidden values) or 101 to 111 (ignores

hidden values) that specifies which function to use in calculating subtotals within a list. Function_num(includes hidden values)

Function_num(ignores hidden values)

Function

1 101 AVERAG

Page 4: Syntax and Purpose of Functions

E2 102 COUNT3 103 COUNTA4 104 MAX5 105 MIN6 106 PRODUC

T7 107 STDEV8 108 STDEVP9 109 SUM10 110 VAR11 111 VARP Ref1 Required. The first named range or reference for which you want the subtotal. Ref2,... Optional. Named ranges or references 2 to 254 for which you want the subtotal. If there are other subtotals within ref1, ref2,… (or nested subtotals), these nested subtotals are

ignored to avoid double counting. For the function_num constants from 1 to 11, the SUBTOTAL function includes the values of rows

hidden by the Hide Rows command under the Hide & Unhide submenu of the Format command in the Cells group on the Home tab. Use these constants when you want to subtotal hidden and nonhidden numbers in a list. For the function_Num constants from 101 to 111, the SUBTOTAL function ignores values of rows hidden by the Hide Rows command. Use these constants when you want to subtotal only nonhidden numbers in a list.

The SUBTOTAL function ignores any rows that are not included in the result of a filter, no matter which function_num value you use.

The SUBTOTAL function is designed for columns of data, or vertical ranges. It is not designed for rows of data, or horizontal ranges. For example, when you subtotal a horizontal range using a function_num of 101 or greater, such as SUBTOTAL(109,B2:G2), hiding a column does not affect the subtotal. But, hiding a row in a subtotal of a vertical range does affect the subtotal.

If any of the references are 3-D references, SUBTOTAL returns the #VALUE! error value.

123456

7

8

A BData1201015023Formula Description (Result)=SUBTOTAL(9,A2:A5)

Subtotal of the column above using the SUM function (303)

=SUBTOTAL(1,A2:A5)

Subtotal of the column above using the AVERAGE function (75.75)

IX. SumThe SUM function adds all the numbers that you specify as arguments. Each argument can be a range, a cell reference, an array, a constant, a formula, or the result from another function. For example, SUM(A1:A5) adds all the numbers that are contained in cells A1 through A5. For another example, SUM(A1, A3, A5) adds the numbers that are contained in cells A1, A3, and A5.SUM(number1,[number2],...])The SUM function syntax has the following arguments:

number1 Required. The first number argument that you want to add.

Page 5: Syntax and Purpose of Functions

number2,,... Optional. Number arguments 2 to 255 that you want to add.If an argument is an array or reference, only numbers in that array or reference are counted. Empty

cells, logical values, or text in the array or reference are ignored. If any arguments are error values, or if any arguments are text that cannot be translated into

numbers, Excel displays an error.

1234567

8

9

10

11

12

A B CData-51530'5TRUEFormula Description Resu

lt=SUM(3, 2) Adds 3 and 2. 5=SUM("5", 15, TRUE)

Adds 5, 15 and 1. The text value "5" is first translated into a number, and the logical value TRUE is first translated into the number 1.

21

=SUM(A2:A4)

Adds the values in cells A2 through A4. 40

=SUM(A2:A4, 15)

Adds the values in cells A2 through A4, and then adds 15 to that result.

55

=SUM(A5,A6, 2)

Adds the values in cells A5 and A6, and then adds 2 to that result. Because non-numeric values in references are not translated — the value in cell A5 ('5) and the value in cell A6 (TRUE) are both treated as text — the values in those cells are ignored.

X. Sumif You use the SUMIF function to sum the values in a range that meet criteria that you specify. For example, suppose that in a column that contains numbers, you want to sum only the values that are larger than 5. You can use the following formula:=SUMIF(B2:B25,">5")In this example, the criteria is applied the same values that are being summed. If you want, you can apply the criteria to one range and sum the corresponding values in a different range. For example, the formula =SUMIF(B2:B5, "John", C2:C5) sums only the values in the range C2:C5, where the corresponding cells in the range B2:B5 equal "John."SUMIF(range, criteria, [sum_range])The SUMIF function syntax has the following arguments:

range Required. The range of cells that you want evaluated by criteria. Cells in each range must be numbers or names, arrays, or references that contain numbers. Blank and text values are ignored.

criteria Required. The criteria in the form of a number, expression, a cell reference, text, or a function that defines which cells will be added. For example, criteria can be expressed as 32, ">32", B5, 32, "32", "apples", or TODAY(). IMPORTANT Any text criteria or any criteria that includes logical or mathematical symbols must be enclosed in double quotation marks ("). If the criteria is numeric, double quotation marks are not required.

sum_range Optional. The actual cells to add, if you want to add cells other than those specified in the range argument. If the sum_range argument is omitted, Excel adds the cells that are specified in the range argument (the same cells to which the criteria is applied).NOTES

Page 6: Syntax and Purpose of Functions

The sum_range argument does not have to be the same size and shape as the range argument. The actual cells that are added are determined by using theupper leftmost cell in the sum_range argument as the beginning cell, and then including cells that correspond in size and shape to the range argument. For example:

If range is

And sum_range is

Then the actual cells are

A1:A5 B1:B5 B1:B5A1:A5 B1:B3 B1:B5A1:B4 C1:D4 C1:D4A1:B4 C1:C2 C1:D4

You can use the wildcard characters — the question mark (?) and asterisk (*) — as the criteria 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 (~) preceding the character.

123456

7

8

9

10

A B CProperty Value Commission Data100,000 7,000 250,0

00200,000 14,000300,000 21,000400,000 28,000Formula Description Resul

t=SUMIF(A2:A5,">160000",B2:B5)

Sum of the commissions for property values over 160,000.

63,000

=SUMIF(A2:A5,">160000") Sum of the property values over 160,000. 900,000

=SUMIF(A2:A5,300000,B2:B5)

Sum of the commissions for property values equal to 300,000.

21,000

=SUMIF(A2:A5,">" & C2,B2:B5)

Sum of the commissions for property values greater than the value in C2.

49,000

12345678

9

10

11

1

A B CCategory Food Sale

sVegetables Tomatoes 2300Vegetables Celery 5500Fruits Oranges 800

Butter 400Vegetables Carrots 4200Fruits Apples 1200Formula Description Resu

lt=SUMIF(A2:A7,"Fruits",C2:C7) Sum of the sales of all foods in the "Fruits"

category.2000

=SUMIF(A2:A7,"Vegetables",C2:C7)

Sum of the sales of all foods in the "Vegetables" category.

12000

=SUMIF(B2:B7,"*es",C2:C7) Sum of the sales of all foods that end in "es" (Tomatoes, Oranges, and Apples).

4300

=SUMIF(A2:A7,"",C2:C7) Sum of the sales of all foods that do not have

Page 7: Syntax and Purpose of Functions

2 a category specified.

Subtotal

Returns a subtotal in a list or database. It is generally easier to create a list with subtotals by using the Subtotal command in the Outline group on the Data tab. Once the subtotal list is created, you can modify it by editing the SUBTOTAL function.SUBTOTAL(function_num,ref1,[ref2],...])The SUBTOTAL function syntax has the following arguments:

Function_num Required. The number 1 to 11 (includes hidden values) or 101 to 111 (ignores hidden values) that specifies which function to use in calculating subtotals within a list. Function_num(includes hidden values)

Function_num(ignores hidden values)

Function

1 101 AVERAGE

2 102 COUNT3 103 COUNTA4 104 MAX5 105 MIN6 106 PRODUC

T7 107 STDEV8 108 STDEVP9 109 SUM10 110 VAR11 111 VARPRef1 Required. The first named range or reference for which you want the subtotal. Ref2,... Optional. Named ranges or references 2 to 254 for which you want the subtotal.If there are other subtotals within ref1, ref2,… (or nested subtotals), these nested subtotals are ignored to avoid double counting. For the function_num constants from 1 to 11, the SUBTOTAL function includes the values of rows hidden by the Hide Rows command under the Hide & Unhide submenu of the Format command in the Cells group on the Home tab. Use these constants when you want to subtotal hidden and nonhidden numbers in a list. For the function_Num constants from 101 to 111, the SUBTOTAL function ignores values of rows hidden by the Hide Rows command. Use these constants when you want to subtotal only nonhidden numbers in a list. The SUBTOTAL function ignores any rows that are not included in the result of a filter, no matter which function_num value you use. The SUBTOTAL function is designed for columns of data, or vertical ranges. It is not designed for rows of data, or horizontal ranges. For example, when you subtotal a horizontal range using a function_num of 101 or greater, such as SUBTOTAL(109,B2:G2), hiding a column does not affect the subtotal. But, hiding a row in a subtotal of a vertical range does affect the subtotal. If any of the references are 3-D references, SUBTOTAL returns the #VALUE! error value.

Example1234

A BData12010

Page 8: Syntax and Purpose of Functions

56

7

8

15023Formula Description (Result)=SUBTOTAL(9,A2:A5)

Subtotal of the column above using the SUM function (303)

=SUBTOTAL(1,A2:A5)

Subtotal of the column above using the AVERAGE function (75.75)

II. Statistical Functions

i. Average: Returns the average (arithmetic mean) of the arguments. For example, if the range A1:A20 contains numbers, the formula =AVERAGE(A1:A20) returns the average of those numbers.

AVERAGE(number1, [number2], ...)The AVERAGE function syntax has the following arguments:

Number1 Required. The first number, cell reference, or range for which you want the average. Number2, ... Optional. Additional numbers, cell references or ranges for which you want the

average, up to a maximum of 255.Arguments can either be numbers or names, ranges, or cell references that contain numbers. Logical values and text representations of numbers that you type directly into the list of arguments

are counted. If a range or cell reference argument contains text, logical values, or empty cells, those values are

ignored; however, cells with the value zero are included. Arguments that are error values or text that cannot be translated into numbers cause errors.

1234567

8

9

10

A B CData10 15 3279272Formula Description Resu

lt=AVERAGE(A2:A6)

Average of the numbers in cells A2 through A6. 11

=AVERAGE(A2:A6, 5)

Average of the numbers in cells A2 through A6 and the number 5.

10

=AVERAGE(A2:C2)

Average of the numbers in cells A2 through C2.

ii. Averagea: Calculates the average (arithmetic mean) of the values in the list of arguments. AVERAGEA(value1, [value2], ...)The AVERAGEA function syntax has the following arguments:

Value1, value2, ... Value1 is required, subsequent values are optional. 1 to 255 cells, ranges of cells, or values for which you want the average.

Page 9: Syntax and Purpose of Functions

Arguments can be the following: numbers; names, arrays, or references that contain numbers; text representations of numbers; or logical values, such as TRUE and FALSE, in a reference.

Logical values and text representations of numbers that you type directly into the list of arguments are counted.

Arguments that contain TRUE evaluate as 1; arguments that contain FALSE evaluate as 0 (zero). Array or reference arguments that contain text evaluate as 0 (zero). Empty text ("") evaluates as 0

(zero). If an argument is an array or reference, only values in that array or reference are used. Empty cells

and text values in the array or reference are ignored. Arguments that are error values or text that cannot be translated into numbers cause errors. If you do not want to include logical values and text representations of numbers in a reference as

part of the calculation, use the AVERAGE function.

1234567

8

9

A BData10792Not availableFormula Description (Result)=AVERAGEA(A2:A6) Average of the numbers above, and the text "Not Available". The cell

with the text "Not available" is used in the calculation. (5.6)=AVERAGEA(A2:A5,A7)

Average of the numbers above, and the empty cell. (7)

iii. MAX : MAX(number1, [number2], ...)

The MAX function syntax has the following arguments:Number1, number2, ... Number1 is required, subsequent numbers are optional. 1 to 255 numbers

for which you want to find the maximum value.Arguments can either be numbers or names, arrays, or references that contain numbers. Logical values and text representations of numbers that you type directly into the list of arguments

are counted. If an argument is an array or reference, only numbers in that array or reference are used. Empty

cells, logical values, or text in the array or reference are ignored. If the arguments contain no numbers, MAX returns 0 (zero). Arguments that are error values or text that cannot be translated into numbers cause errors.

123456789

A BData1079272Formula Description (Result)=MAX(A2:A6) Largest of the numbers above (27)=MAX(A2:A6, 30)

Largest of the numbers above and 30 (30)

Page 10: Syntax and Purpose of Functions

iv. MAXA: Returns the largest value in a list of arguments.MAXA(value1,[value2],...)

The MAXA function syntax has the following arguments:Value1 Required. The first number argument for which you want to find the largest value. Value2,... Optional. Number arguments 2 to 255 for which you want to find the largest value.Arguments can be the following: numbers; names, arrays, or references that contain numbers; text

representations of numbers; or logical values, such as TRUE and FALSE, in a reference. Logical values and text representations of numbers that you type directly into the list of arguments

are counted. If an argument is an array or reference, only values in that array or reference are used. Empty cells

and text values in the array or reference are ignored. Arguments that are error values or text that cannot be translated into numbers cause errors. Arguments that contain TRUE evaluate as 1; arguments that contain text or FALSE evaluate as 0

(zero). If the arguments contain no values, MAXA returns 0 (zero).

V. MINReturns the smallest value in the list of arguments. MINA(value1, [value2], ...)The MINA function syntax has the following arguments:

Value1, value2, ... Value1 is required, subsequent values are optional. 1 to 255 values for which you want to find the smallest value.

Arguments can be the following: numbers; names, arrays, or references that contain numbers; text representations of numbers; or logical values, such as TRUE and FALSE, in a reference.

If an argument is an array or reference, only values in that array or reference are used. Empty cells and text values in the array or reference are ignored.

Arguments that contain TRUE evaluate as 1; arguments that contain text or FALSE evaluate as 0 (zero).

Arguments that are error values or text that cannot be translated into numbers cause errors. If the arguments contain no values, MINA returns 0.

12345678

A BDataFALSE0.20.50.40.8Formula Description (Result)=MINA(A2:A6)

Smallest of the numbers above. FALSE evaluates to 0 (0)

VI. STDEV

Estimates standard deviation based on a sample. The standard deviation is a measure of how widely values are dispersed from the average value (the mean). STDEV(number1,[number2],...])The STDEV function syntax has the following arguments:

Number1 Required. The first number argument corresponding to a sample of a population. Number2, ... Optional. Number arguments 2 to 255 corresponding to a sample of a population. You

can also use a single array or a reference to an array instead of arguments separated by commas.STDEV assumes that its arguments are a sample of the population. If your data represents the entire

population, then compute the standard deviation using STDEVP.

Page 11: Syntax and Purpose of Functions

The standard deviation is calculated using the "n-1" method. Arguments can either be numbers or names, arrays, or references that contain numbers. Logical values and text representations of numbers that you type directly into the list of arguments

are counted. If an argument is an array or reference, only numbers in that array or reference are counted. Empty

cells, logical values, text, or error values in the array or reference are ignored. Arguments that are error values or text that cannot be translated into numbers cause errors. If you want to include logical values and text representations of numbers in a reference as part of the

calculation, use the STDEVA function. STDEV uses the following formula:

where x is the sample mean AVERAGE(number1,number2,…) and n is the sample size.

12345678910111213

AStrength

1345

1301

1368

1322

1310

1370

1318

1350

1303

1299

Formula Description (Result)=STDEV(A2:A11)

Standard deviation of breaking strength (27.46392)

Vii. VAREstimates variance based on a sample. VAR(number1,[number2],...])The VAR function syntax has the following arguments:

Number1 Required. The first number argument corresponding to a sample of a population.

Page 12: Syntax and Purpose of Functions

Number2, ... Optional. Number arguments 2 to 255 corresponding to a sample of a population.VAR assumes that its arguments are a sample of the population. If your data represents the entire

population, then compute the variance by using VARP. Arguments can either be numbers or names, arrays, or references that contain numbers. Logical values, and text representations of numbers that you type directly into the list of arguments

are counted. If an argument is an array or reference, only numbers in that array or reference are counted. Empty

cells, logical values, text, or error values in the array or reference are ignored. Arguments that are error values or text that cannot be translated into numbers cause errors. If you want to include logical values and text representations of numbers in a reference as part of the

calculation, use the VARA function. VAR uses the following formula:

where x is the sample mean AVERAGE(number1,number2,…) and n is the sample size.

12345678910111213

AStrength

1345

1301

1368

1322

1310

1370

1318

1350

1303

1299

Formula Description (Result)=VAR(A2:A11)

Variance for the breaking strength of the tools (754.2667)

vii. Count

Page 13: Syntax and Purpose of Functions

The COUNT function counts the number of cells that contain numbers, and counts numbers within the list of arguments. Use the COUNT function to get the number of entries in a number field that is in a range or array of numbers. For example, you can enter the following formula to count the numbers in the range A1:A20:=COUNT(A1:A20)COUNT(value1, [value2], ...)The COUNT function syntax has the following arguments:

value1 Required. The first item, cell reference, or range within which you want to count numbers. value2, ... Optional. Up to 255 additional items, cell references, or ranges within which you want to

count numbers. Arguments that are numbers, dates, or a text representation of numbers (for example, a number

enclosed in quotation marks, such as "1") are counted. Logical values and text representations of numbers that you type directly into the list of arguments

are counted. Arguments that are error values or text that cannot be translated into numbers are not counted. If an argument is an array or reference, only numbers in that array or reference are counted. Empty

cells, logical values, text, or error values in the array or reference are not counted. If you want to count logical values, text, or error values, use the COUNTA function. If you want to count only numbers that meet certain criteria, use the COUNTIF function or the

COUNTIFS function.

123456789

10

11

12

A B CDataSales12/8/20081922.24TRUE#DIV/0!Formula Description Resu

lt=COUNT(A2:A8)

Counts the number of cells that contain numbers in cells A2 through A8.

3

=COUNT(A5:A8)

Counts the number of cells that contain numbers in cells A5 through A8.

2

=COUNT(A2:A8,2)

Counts the number of cells that contain numbers in cells A2 through A8, and the value 2

4

viii. COUNTA

The COUNTA function counts the number of cells that are not empty in a range.COUNTA(value1, [value2], ...)The COUNTA function syntax has the following arguments:

value1 Required. The first argument representing the values that you want to count. value2, ... Optional. Additional arguments representing the values that you want to count, up to a

maximum of 255 arguments.The COUNTA function counts cells containing any type of information, including error values and

empty text (""). For example, if the range contains a formula that returns an empty string, the COUNTA function counts that value. The COUNTA function does not count empty cells.

Page 14: Syntax and Purpose of Functions

If you do not need to count logical values, text, or error values (in other words, if you want to count only cells that contain numbers), use the COUNT function.

If you want to count only cells that meet certain criteria, use the COUNTIF function or the COUNTIFS function.

123456789

10

A B CDataSales12/8/20081922.24TRUE#DIV/0!Formula Description Resu

lt=COUNTA(A2:A8)

Counts the number of nonblank cells in cells A2 through A8.

ix. Countblank

Counts empty cells in a specified range of cells.COUNTBLANK(range)The COUNTBLANK function syntax has the following arguments:

Range Required. The range from which you want to count the blank cells.Cells with formulas that return "" (empty text) are also counted. Cells with zero values are not counted.1.

123456

7

A BData Data6 =IF(B4<30,"",B4)

274 34Formula Description (Result)=COUNTBLANK(A2:B5)

Counts empty cells in the range above. The formula returns empty text. (4)

x. Countif

The COUNTIF function counts the number of cells within a range that meet a single criterion that you specify. For example, you can count all the cells that start with a certain letter, or you can count all the cells that contain a number that is larger or smaller than a number you specify. For example, suppose you have a worksheet that contains a list of tasks in column A, and the first name of the person assigned to each task in column B. You can use the COUNTIF function to count how many times a person's name appears in column B and, in that way, determine how many tasks are assigned to that person. For example:=COUNTIF(B2:B25,"Nancy")COUNTIF(range, criteria)The COUNTIF function syntax has the following arguments:

range Required. One or more cells to count, including numbers or names, arrays, or references that contain numbers. Blank and text values are ignored.

criteria Required. A number, expression, cell reference, or text string that defines which cells will be counted. For example, criteria can be expressed as 32, ">32", B4, "apples", or "32".

Page 15: Syntax and Purpose of Functions

You can use the wildcard characters — the question mark (?) and the asterisk (*) — in criteria. A question mark matches any single character, and an asterisk matches any sequence of characters. If you want to find an actual question mark or asterisk, type a tilde (~) before the character.

Criteria are case insensitive; for example, the string "apples" and the string "APPLES" will match the same cells.

123456

7

8

9

10

11

12

A B CData Dataapples 32oranges 54peaches 75apples 86Formula Description Resu

lt=COUNTIF(A2:A5,"apples") Number of cells with apples in cells

A2 through A5.2

=COUNTIF(A2:A5,A4) Number of cells with peaches in cells A2 through A5.

1

=COUNTIF(A2:A5,A3)+COUNTIF(A2:A5,A2)

Number of cells with oranges and apples in cells A2 through A5.

3

=COUNTIF(B2:B5,">55") Number of cells with a value greater than 55 in cells B2 through B5.

2

=COUNTIF(B2:B5,"<>"&B4) Number of cells with a value not equal to 75 in cells B2 through B5.

3

=COUNTIF(B2:B5,">=32")-COUNTIF(B2:B5,">85")

Number of cells with a value greater than or equal to 32 and less than or equal to 85 in cells B2 through B5.

3

EXAMPLE 2: COUNTIF FORMULAS USING WILDCARD CHARACTERS AND HANDLING BLANK VALUES

12345678

9

10

11

A B CData Dataapples Yesoranges NOpeaches Noapples yesFormula Description Result=COUNTIF(A2:A7,"*es") Number of cells ending with the

letters "es" in cells A2 through A7.4

=COUNTIF(A2:A7,"?????es") Number of cells ending with the letters "les" and having exactly 7 letters in cells A2 through A7.

2

=COUNTIF(A2:A7,"*") Number of cells containing any text in cells A2 through A7.

4

=COUNTIF(A2:A7,"<>"&"*") Number of cells not containing text in cells A2 through A7.

2

=COUNTIF(B2:B7,"No") / ROWS(B2:B7)

The average number of No votes (including blank cells) in cells B2 through B7.

0.333333333

=COUNTIF(B2:B7,"Yes") / (ROWS(B2:B7) -COUNTIF(B2:B7,

The average number of Yes votes (excluding blank cells) in cells B2

0.5

Page 16: Syntax and Purpose of Functions

12

13

14

"<>"&"*")) through B7.

xi. Large

Returns the k-th largest value in a data set. You can use this function to select a value based on its relative standing. For example, you can use LARGE to return the highest, runner-up, or third-place score.LARGE(array, k)The LARGE function syntax has the following arguments:

Array Required. The array or range of data for which you want to determine the k-th largest value. K Required. The position (from the largest) in the array or cell range of data to return.If array is empty, LARGE returns the #NUM! error value. If k ≤ 0 or if k is greater than the number of data points, LARGE returns the #NUM! error value.

If n is the number of data points in a range, then LARGE(array,1) returns the largest value, and LARGE(array,n) returns the smallest value.1.

123456789

A BData Data3 45 23 45 64 7Formula Description (Result)=LARGE(A2:B6,3)

3rd largest number in the numbers above (5)

=LARGE(A2:B6,7)

7th largest number in the numbers above (4)

xii. Small

Returns the k-th smallest value in a data set. Use this function to return values with a particular relative standing in a data set.SMALL(array, k)The SMALL function syntax has the following arguments:

Array Required. An array or range of numerical data for which you want to determine the k-th smallest value.

K Required. The position (from the smallest) in the array or range of data to return.If array is empty, SMALL returns the #NUM! error value. If k ≤ 0 or if k exceeds the number of data points, SMALL returns the #NUM! error value.

Page 17: Syntax and Purpose of Functions

If n is the number of data points in array, SMALL(array,1) equals the smallest value, and SMALL(array,n) equals the largest value.

12345678910111213

A BData Data3 14 45 82 33 74 126 544 87 23Formula Description (Result)=SMALL(A2:A10,4)

4th smallest number in first column (4)

=SMALL(B2:B10,2)

2nd smallest number in the second column (3)

Frequency Calculates how often values occur within a range of values, and then returns a vertical array of numbers. For example, use FREQUENCY to count the number of test scores that fall within ranges of scores. Because FREQUENCY returns an array, it must be entered as an array formula.FREQUENCY(data_array, bins_array)The FREQUENCY function syntax has the following arguments:

Data_array Required. An array of or reference to a set of values for which you want to count frequencies. If data_array contains no values, FREQUENCY returns an array of zeros.

Bins_array Required. An array of or reference to intervals into which you want to group the values in data_array. If bins_array contains no values, FREQUENCY returns the number of elements in data_array.

FREQUENCY is entered as an array formula after you select a range of adjacent cells into which you want the returned distribution to appear.

The number of elements in the returned array is one more than the number of elements in bins_array. The extra element in the returned array returns the count of any values above the highest interval. For example, when counting three ranges of values (intervals) that are entered into three cells, be sure to enter FREQUENCY into four cells for the results. The extra cell returns the number of values in data_array that are greater than the third interval value.

FREQUENCY ignores blank cells and text. Formulas that return arrays must be entered as array formulas.

12345678

A BScores Bins79 7085 7978 89855081

Page 18: Syntax and Purpose of Functions

91011

121314

15

958897Formula Description (Result)=FREQUENCY(A2:A10, B2:B4)

Number of scores less than or equal to 70 (1)Number of scores in the bin 71-79 (2)Number of scores in the bin 80-89 (4)Number of scores greater than or equal to 90 (2)

NOTE The formula in the example must be entered as an array formula. After copying the example to a blank worksheet, select the range A12:A15, press F2, and then press CTRL+SHIFT+ENTER. If the formula is not entered as an array formula, there will be only one result in cell A12 (1).

Transpose The TRANSPOSE function returns a vertical range of cells as a horizontal range, or vice versa. The TRANSPOSE function must be entered as an array formula in a range that has the same number of rows and columns, respectively, as the source range has columns and rows. Use TRANSPOSE to shift the vertical and horizontal orientation of an array or range on a worksheet.TRANSPOSE(array)The TRANSPOSE function syntax has the following argument:

array Required. An array or range of cells on a worksheet that you want to transpose. The transpose of an array is created by using the first row of the array as the first column of the new array, the second row of the array as the second column of the new array, and so on.

EXAMPLE 1123

4

56

A B CData Data Data1 2 3Formula Description Resu

lt=TRANSPOSE($A$2:$C$2)

Value from first column 1

Value from second column

2

Value from third column

3

IMPORTANT The formula shown in the example must be entered as an array formula for the TRANSPOSE function to work as expected. After copying the example to a blank worksheet, select the range A4:A6, starting with the formula cell. Press F2, and then press CTRL+SHIFT+ENTER. If the formula is not entered as an array formula, the single result is 1.EXAMPLE 2Some functions, such as LINEST, return horizontal arrays. The LINEST function returns a horizontal array of the slope and Y-intercept for a line. The following formula returns a vertical array of the slope and Y-intercept by using the LINEST function.

12

A B CKnown y Known x

Page 19: Syntax and Purpose of Functions

345678

1 09 45 27 3Formula Descripti

onResult

=TRANSPOSE(LINEST(A2:A5,B2:B5,,FALSE))

Slope 2

Y-intercept

1

IMPORTANT The formula shown in the example must be entered as an array formula for the TRANSPOSE function to work as expected. After copying the example to a blank worksheet, select the range A7:A8, starting with the formula cell. Press F2, and then press CTRL+SHIFT+ENTER. If the formula is not entered as an array formula, the single result is 2.

Text Functions

a. LEN LEN returns the number of characters in a text string.

LEN always counts each character, whether single-byte or double-byte, as 1, no matter what the default language setting is. LEN(text)

Text Required. The text whose length you want to find. Spaces count as characters.

Example12345678

A BDataPhoenix, AZOneFormula Description (Result)=LEN(A2) Length of the first string (11)=LEN(A3) Length of the second string (0)=LEN(A4) Length of the third string, which includes 5

spaces (8)

b. LEFT LEFT returns the first character or characters in a text string, based on the number of characters you specify.

LEFT always counts each character, whether single-byte or double-byte, as 1, no matter what the default language setting is. LEFT(text, [num_chars])

Text Required. The text string that contains the characters you want to extract. Num_chars Optional. Specifies the number of characters you want LEFT to extract.

Num_chars must be greater than or equal to zero. If num_chars is greater than the length of text, LEFT returns all of text. If num_chars is omitted, it is assumed to be 1.

Page 20: Syntax and Purpose of Functions

Num_bytes Optional. Specifies the number of characters you want LEFTB to extract, based on bytes.

Example123456

A BDataSale PriceSwedenFormula Description (Result)=LEFT(A2,4)

First four characters in the first string (Sale)

=LEFT(A3)

First character in the second string (S)

c. RIGHT RIGHT returns the last character or characters in a text string, based on the number of characters you specify.RIGHT always counts each character, whether single-byte or double-byte, as 1, no matter what the default language setting is. RIGHT(text,[num_chars])

Text Required. The text string containing the characters you want to extract. Num_chars Optional. Specifies the number of characters you want RIGHT to extract. Num_chars must be greater than or equal to zero. If num_chars is greater than the length of text, RIGHT returns all of text. If num_chars is omitted, it is assumed to be 1.

Example

123456

A BDataSale PriceStock NumberFormula Description (Result)=RIGHT(A2,5)

Last 5 characters of the first string (Price)

=RIGHT(A3) Last character of the second string (r)

d. 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.

MID always counts each character, whether single-byte or double-byte, as 1, no matter what the default language setting is. MID(text, start_num, num_chars)

Text Required. The text string containing the characters you want to extract. Start_num Required. The position of the first character you want to extract in text. The first character

in text has start_num 1, and so on. Num_chars Required. Specifies the number of characters you want MID to return from text. If start_num is greater than the length of text, MID returns "" (empty text).

Page 21: Syntax and Purpose of Functions

If start_num is less than the length of text, but start_num plus num_chars exceeds the length of text, MID returns the characters up to the end of text.

If start_num is less than 1, MID returns the #VALUE! error value. If num_chars is negative, MID returns the #VALUE! error value.

Example123

4

5

6

A BDataFluid FlowFormula Description (Result)=MID(A2,1,5)

Five characters from the string above, starting at the first character (Fluid)

=MID(A2,7,20)

Twenty characters from the string above, starting at the seventh (Flow)

=MID(A2,20,5)

Because the starting point is greater than the length of the string, empty text is returned ()

e. Lower Converts all uppercase letters in a text string to lowercase.

LOWER(text)The LOWER function syntax has the following arguments:

Text Required. The text you want to convert to lowercase. LOWER does not change characters in text that are not letters.

Example123456

A BDataE. E. CummingsApt. 2BFormula Description (Result)=LOWER(A2) Lower case of first string (e. e.

cummings)=LOWER(A3) Lower case of last string (apt. 2b)

f. Upper Converts text to uppercase.

UPPER(text)The UPPER function syntax has the following arguments:

Text Required. The text you want converted to uppercase. Text can be a reference or text string.

Example123

A BDatatotal

Page 22: Syntax and Purpose of Functions

456

YieldFormula Description (Result)=UPPER(A2)

Upper case of first string (TOTAL)

=UPPER(A3)

Upper case of second string (YIELD)

g. Proper Capitalizes the first letter in a text string and any other letters in text that follow any character other than a letter. Converts all other letters to lowercase letters.

PROPER(text)The PROPER function syntax has the following arguments:

Text Required. Text enclosed in quotation marks, a formula that returns text, or a reference to a cell containing the text you want to partially capitalize.

Example12345678

A BDatathis is a TITLE2-cent's worth76BudGetFormula Description (Result)=PROPER(A2)

Proper case of first string (This Is A Title)

=PROPER(A3)

Proper case of second string (2-Cent'S Worth)

=PROPER(A4)

Proper case of third string (76Budget)

h. Search

The SEARCH and SEARCHB functions locate one text string within a second text string, and return the number of the starting position of the first text string from the first character of the second text string. For example, to find the position of the letter "n" in the word "printer", you can use the following function:=SEARCH("n","printer")This function returns 4 because "n" is the fourth character in the word "printer."You can also search for words within other words. For example, the function=SEARCH("base","database")returns 5, because the word "base" begins at the fifth character of the word "database". You can use the SEARCH and SEARCHB functions to determine the location of a character or text string within another text string, and then use the MID and MIDB functions to return the text, or use the REPLACE and REPLACEB functions to change the text. These functions are demonstrated in Example 1 in this article.IMPORTANT The SEARCH function is intended for use with languages that use the single-byte character set (SBCS), whereas the SEARCHB function is intended for use with languages that use the double-byte character set (DBCS). The default language setting on your computer affects the return value in the following way:

Page 23: Syntax and Purpose of Functions

SEARCH always counts each character, whether single-byte or double-byte, as 1, no matter what the default language setting is. SEARCH(find_text,within_text,[start_num])The SEARCH function have the following arguments:

find_text Required. The text that you want to find. within_text Required. The text in which you want to search for the value of the find_text argument. start_num Optional. The character number in the within_text argument at which you want to start

searching.

RemarkThe SEARCH functions is not case sensitive. If you want to do a case sensitive search, you can use

FIND. You can use the wildcard characters — the question mark (?) and asterisk (*) — in the find_text

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.

If the value of find_text is not found, the #VALUE! error value is returned. If the start_num argument is omitted, it is assumed to be 1. If start_num is not greater than 0 (zero) or is greater than the length of the within_text argument,

the #VALUE! error value is returned. Use start_num to skip a specified number of characters. Using the SEARCH function as an

example, suppose you are working with the text string "AYF0093.YoungMensApparel". To find the position of the first "Y" in the descriptive part of the text string, set start_num equal to 8 so that the serial number portion of the text (in this case, "AYF0093") is not searched. The SEARCH function starts the search operation at the eighth character position, finds the character that is specified in the find_text argument at the next position, and returns the number 9. The SEARCH function always returns the number of characters from the start of the within_text argument, counting the characters you skip if the start_num argument is greater than 1.

Examples123456

7

8

9

10

1

A B CDataStatementsProfit MarginMarginThe "boss" is here.Formula Description Result=SEARCH("e",A2,6) Position of the

first "e" in the string in cell A2, starting at the sixth position.

7

=SEARCH(A4,A3) Position of "margin" (string for which to search is cell A4) in "Profit Margin" (cell in which to search is A3).

8

=REPLACE(A3,SEARCH(A4,A3),6,"Amount") Replaces "Margin" with "Amount" by first searching for the position of "Margin" in cell A3, and

Profit Amount

Page 24: Syntax and Purpose of Functions

1

12

then replacing that character and the next five characters with the string "Amount."

=MID(A3,SEARCH(" ",A3)+1,4) Returns the first four characters that follow the first space character in "Profit Margin" (cell A3).

Marg

=SEARCH("""",A5) Position of the first double quotation mark (") in cell A5.

5

=MID(A5,SEARCH("""",A5)+1,SEARCH("""",A5,SEARCH("""",A5)+1)-SEARCH("""",A5)-1)

Returns only the text enclosed in the double quotation marks in cell A5.

boss

i. FindFIND locate one text string within a second text string, and return the number of the starting position of the first text string from the first character of the second text string.

FIND always counts each character, whether single-byte or double-byte, as 1, no matter what the default language setting is. FIND(find_text, within_text, [start_num])The FIND function syntax has the following arguments:

Find_text Required. The text you want to find. Within_text Required. The text containing the text you want to find. Start_num Optional. Specifies the character at which to start the search. The first character in

within_text is character number 1. If you omit start_num, it is assumed to be 1.FIND is case sensitive and don't allow wildcard characters. If you don't want to do a case sensitive

search or use wildcard characters, you can use SEARCH If find_text is "" (empty text), FIND matches the first character in the search string (that is, the

character numbered start_num or 1). Find_text cannot contain any wildcard characters. If find_text does not appear in within_text, FIND and FINDB return the #VALUE! error value. If start_num is not greater than zero, FIND and FINDB return the #VALUE! error value. If start_num is greater than the length of within_text, FIND and FINDB return the #VALUE! error

value. Use start_num to skip a specified number of characters. Using FIND as an example, suppose you

are working with the text string "AYF0093.YoungMensApparel". To find the number of the first "Y" in the descriptive part of the text string, set start_num equal to 8 so that the serial-number portion of the text is not searched. FIND begins with character 8, finds find_text at the next character, and returns the number 9. FIND always returns the number of characters from the start of within_text, counting the characters you skip if start_num is greater than 1.

Example12345

A BDataMiriam McGovernFormula Description (Result)

Page 25: Syntax and Purpose of Functions

6=FIND("M",A2) Position of the first "M" in the string above (1)=FIND("m",A2) Position of the first "m" in the string above (6)=FIND("M",A2,3)

Position of the first "M" in the string above, starting with the third character (8)

Concatenate

The CONCATENATE function joins up to 255 text strings into one text string. The joined items can be text, numbers, cell references, or a combination of those items. For example, if your worksheet contains a person's first name in cell A1 and the person's last name in cell B1, you can combine the two values in another cell by using the following formula: =CONCATENATE(A1," ",B1)The second argument in this example (" ") is a space character. You must specify any spaces or punctuation that you want to appear in the results as an argument that is enclosed in quotation marks.

SyntaxCONCATENATE(text1, [text2], ...)The CONCATENATE function syntax has the following arguments:

Text1 Required. The first text item to be concatenated. Text2, ... Optional. Additional text items, up to a maximum of 255 items. The items must be

separated by commas. NOTE You can also use the ampersand (&) calculation operator instead of the CONCATENATE function to join text items. For example,=A1 & B1returns the same value as=CONCATENATE(A1, B1)

12345

6

7

8

A B CDatabrook trout Andreas HauserSpecies Fourth Pine32Formula Description Result=CONCATENATE("Stream population for ", A2, " ", A3, " is ", A4, "/mile")

Creates a sentence by concatenating the data in column A with other text.

Stream population for brook trout species is 32/mile

=CONCATENATE(B2, " ", C2) Concatenates the string in cell B2, a space character, and the value in cell C2.

Andreas Hauser

=CONCATENATE(C2, ", ", B2) Concatenates the string in cell C2, a string consisting of a comma and a space character, and the value in cell B2.

Hauser, Andreas

=CONCATENATE(B3, " & ", C3)

Concatenates the string in cell B3, a string consisting of a space, an ampersand, another space, and the value in cell C3.

Fourth & Pine

=B3 & " & " & C3 Concatenates the same items as the previous example, but by using the ampersand (&) calculation operator instead of the CONCATENATE function.

Page 26: Syntax and Purpose of Functions

ReplaceREPLACE replaces part of a text string, based on the number of characters you specify, with a different text string.REPLACE(old_text, start_num, num_chars, new_text)REPLACEB(old_text, start_num, num_bytes, new_text)The REPLACE function syntax has the following arguments:

Old_text Required. Text in which you want to replace some characters. Start_num Required. The position of the character in old_text that you want to replace with

new_text. Num_chars Required. The number of characters in old_text that you want REPLACE to replace with

new_text. Num_bytes Required. The number of bytes in old_text that you want REPLACEB to replace with

new_text. New_text Required. The text that will replace characters in old_text.

Example12345

6

7

8

A BDataabcdefghijk2009123456Formula Description (Result)=REPLACE(A2,6,5,"*")

Replaces five characters, starting with the sixth character (abcde*k)

=REPLACE(A3,3,2,"10")

Replaces the last two digits of 2009 with 10 (2010)

=REPLACE(A4,1,3,"@")

Replaces the first three characters with @ (@456)

Substitute

Substitutes new_text for old_text in a text string. Use SUBSTITUTE when you want to replace specific text in a text string; use REPLACE when you want to replace any text that occurs in a specific location in a text string.

SyntaxSUBSTITUTE(text, old_text, new_text, [instance_num])The SUBSTITUTE function syntax has the following arguments:

Text Required. The text or the reference to a cell containing text for which you want to substitute characters.

Old_text Required. The text you want to replace. New_text Required. The text you want to replace old_text with. Instance_num Optional. Specifies which occurrence of old_text you want to replace with new_text. If

you specify instance_num, only that instance of old_text is replaced. Otherwise, every occurrence of old_text in text is changed to new_text.

Example123

A BData <Sales Data <

Page 27: Syntax and Purpose of Functions

45

6

7

8

Quarter 1, 2008 <Quarter 1, 2011 <Formula Description (Result)=SUBSTITUTE(A2, "Sales", "Cost")

Substitutes Cost for Sales (Cost Data)

=SUBSTITUTE(A3, "1", "2", 1)

Substitutes first instance of "1" with "2" (Quarter 2, 2008)

=SUBSTITUTE(A4, "1", "2", 3)

Substitutes third instance of "1" with "2" (Quarter 1, 2012)

Trim

Removes all spaces from text except for single spaces between words. Use TRIM on text that you have received from another application that may have irregular spacing.IMPORTANT The TRIM function was designed to trim the 7-bit ASCII space character (value 32) from text. In the Unicode character set, there is an additional space character called the nonbreaking space character that has a decimal value of 160. This character is commonly used in Web pages as the HTML entity, &nbsp;. By itself, the TRIM function does not remove this nonbreaking space character. For an example of how to trim both space characters from text, see Remove spaces and nonprinting characters from text.

SyntaxTRIM(text)The TRIM function syntax has the following arguments:

Text Required. The text from which you want spaces removed.

Example1

2

A BFormula Description (Result)=TRIM(" First Quarter Earnings ")

Removes leading and trailing spaces from the text in the formula (First Quarter Earnings)

CodeReturns a numeric code for the first character in a text string. The returned code corresponds to the character set used by your computer.

Operating environment Character setMacintosh Macintosh character

setWindows ANSI

SyntaxCODE(text)The CODE function syntax has the following arguments:

Text Required. The text for which you want the code of the first character.

123

A BFormula Description (Result)=CODE("A")

Displays the numeric code for A (65)

Page 28: Syntax and Purpose of Functions

=CODE("!")

Displays the numeric code for ! (33)

CharReturns the character specified by a number. Use CHAR to translate code page numbers you might get from files on other types of computers into characters.

Operating environment Character setMacintosh Macintosh character

setWindows ANSI

SyntaxCHAR(number)The CHAR function syntax has the following arguments:

Number Required. A number between 1 and 255 specifying which character you want. The character is from the character set used by your computer.

Example123

A BFormula Description (Result)=CHAR(65)

Displays the 65 character in the set (A)

=CHAR(33)

Displays the 33 character in the set (!)

Look up FunctionsVlookup

You can use the VLOOKUP function to search the first column of a range of cells, and then return a value from any cell on the same row of the range. For example, suppose that you have a list of employees contained in the range A2:C10. The employees' ID numbers are stored in the first column of the range, as shown in the following illustration.

Page 29: Syntax and Purpose of Functions

If you know the employee's ID number, you can use the VLOOKUP function to return either the department or the name of that employee. To obtain the name of employee number 38, you can use the formula =VLOOKUP(38, A2:C10, 3, FALSE). This formula searches for the value 38 in the first column of the range A2:C10, and then returns the value that is contained in the third column of the range and on the same row as the lookup value ("Axel Delgado").The V in VLOOKUP stands for vertical. Use VLOOKUP instead of HLOOKUP when your comparison values are located in a column to the left of the data that you want to find.VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup])The VLOOKUP function syntax has the following arguments:

lookup_value Required. The value to search in the first column of the table or range. The lookup_value argument can be a value or a reference. If the value you supply for the lookup_value argument is smaller than the smallest value in the first column of the table_array argument, VLOOKUP returns the #N/A error value.

table_array Required. The range of cells that contains the data. You can use a reference to a range (for example, A2:D8), or a range name. The values in the first column of table_array are the values searched by lookup_value. These values can be text, numbers, or logical values. Uppercase and lowercase text are equivalent.

col_index_num Required. The column number in the table_array argument from which the matching value must be returned. A col_index_num argument of 1 returns the value in the first column in table_array; a col_index_num of 2 returns the value in the second column in table_array, and so on. If the col_index_num argument is:

Less than 1, VLOOKUP returns the #VALUE! error value. Greater than the number of columns in table_array, VLOOKUP returns the #REF! error

value.range_lookup Optional. A logical value that specifies whether you want VLOOKUP to find an exact

match or an approximate match: If range_lookup is either TRUE or is omitted, an exact or approximate match is returned. If

an exact match is not found, the next largest value that is less than lookup_value is returned. If range_lookup is either TRUE or is omitted, the values in the first column of table_array must be placed in ascending sort order; otherwise, VLOOKUP might not return the correct value.If range_lookup is FALSE, the values in the first column of table_array do not need to be sorted.

If the range_lookup argument is FALSE, VLOOKUP will find only an exact match. If there are two or more values in the first column of table_array that match the lookup_value, the first value found is used. If an exact match is not found, the error value #N/A is returned.

When searching text values in the first column of table_array, ensure that the data in the first column of table_array does not contain leading spaces, trailing spaces, inconsistent use of straight ( ' or " ) and curly ( ‘ or “) quotation marks, or nonprinting characters. In these cases, VLOOKUP might return an incorrect or unexpected value. For more information, see CLEAN function and TRIM function.

When searching number or date values, ensure that the data in the first column of table_array is not stored as text values. In this case, VLOOKUP might return an incorrect or unexpected value.

If range_lookup is FALSE and lookup_value is text, you can use the wildcard characters — the 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 (~) preceding the character.

123456789

A B CDensity Viscosity Temperat

ure0.457 3.55 5000.525 3.25 4000.606 2.93 3000.675 2.75 2500.746 2.57 2000.835 2.38 1500.946 2.17 100

Page 30: Syntax and Purpose of Functions

1011

12

13

14

1.09 1.95 501.29 1.71 0Formula Description Result=VLOOKUP(1,A2:C10,2) Using an approximate match, searches for

the value 1 in column A, finds the largest value less than or equal to 1 in column A which is 0.946, and then returns the value from column B in the same row.

2.17

=VLOOKUP(1,A2:C10,3,TRUE)

Using an approximate match, searches for the value 1 in column A, finds the largest value less than or equal to 1 in column A, which is 0.946, and then returns the value from column C in the same row.

100

=VLOOKUP(0.7,A2:C10,3,FALSE)

Using an exact match, searches for the value 0.7 in column A. Because there is no exact match in column A, an error is returned.

#N/A

=VLOOKUP(0.1,A2:C10,2,TRUE)

Using an approximate match, searches for the value 0.1 in column A. Because 0.1 is less than the smallest value in column A, an error is returned.

#N/A

=VLOOKUP(2,A2:C10,2,TRUE)

Using an approximate match, searches for the value 2 in column A, finds the largest value less than or equal to 2 in column A, which is 1.29, and then returns the value from column B in the same row.

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. 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."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

Page 31: Syntax and Purpose of Functions

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.

RemarkIf 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.

12345

6

7

8

9

10

A B CAxles Bearings Bolt

s4 4 95 7 106 8 11Formula Description (Result)=HLOOKUP("Axles", A1:C4, 2, TRUE)

Looks up Axles in row 1, and returns the value from row 2 that's in the same column. (4)

=HLOOKUP("Bearings", A1:C4, 3, FALSE)

Looks up Bearings in row 1, and returns the value from row 3 that's in the same column. (7)

=HLOOKUP("B", A1:C4, 3, TRUE)

Looks up B in row 1, and returns the value from row 3 that's in the same column. Because B is not an exact match, the next largest value that is less than B is used: Axles. (5)

=HLOOKUP("Bolts", A1:C4, 4)

Looks up Bolts in row 1, and returns the value from row 4 that's in the same column. (11)

=HLOOKUP(3, {1, 2, 3, "a", "b", "c", "d", "e", "f"}, 2, TRUE)

Looks up 3 in the first row of the array constant, and returns the value from row 2 in same column. (c)

Logical Functions

i. If

The IF function returns one value if a condition you specify evaluates to TRUE, and another value if that condition evaluates to FALSE. For example, the formula =IF(A1>10,"Over 10","10 or less") returns "Over 10" if A1 is greater than 10, and "10 or less" if A1 is less than or equal to 10.

SyntaxIF(logical_test, [value_if_true], [value_if_false])The IF function syntax has the following arguments:

logical_test Required. Any value or expression that can be evaluated to TRUE or FALSE. For example, A10=100 is a logical expression; if the value in cell A10 is equal to 100, the expression evaluates to TRUE. Otherwise, the expression evaluates to FALSE. This argument can use any comparison calculation operator.

Page 32: Syntax and Purpose of Functions

value_if_true Optional. The value that you want to be returned if the logical_test argument evaluates to TRUE. For example, if the value of this argument is the text string "Within budget" and the logical_test argument evaluates to TRUE, the IF function returns the text "Within budget." If logical_test evaluates to TRUE and the value_if_true argument is omitted (that is, there is only a comma following the logical_test argument), the IF function returns 0 (zero). To display the word TRUE, use the logical value TRUE for the value_if_true argument.

value_if_false Optional. The value that you want to be returned if the logical_test argument evaluates to FALSE. For example, if the value of this argument is the text string "Over budget" and the logical_test argument evaluates to FALSE, the IF function returns the text "Over budget." If logical_test evaluates to FALSE and the value_if_false argument is omitted, (that is, there is no comma following the value_if_true argument), the IF function returns the logical value FALSE. If logical_test evaluates to FALSE and the value of the value_if_false argument is omitted (that is, in the IF function, there is no comma following the value_if_true argument), the IF function returns the value 0 (zero).

RemarksUp to 64 IF functions can be nested as value_if_true and value_if_false arguments to construct

more elaborate tests. Alternatively, to test many conditions, consider using the LOOKUP, VLOOKUP, HLOOKUP, or CHOOSE functions. (See Example 4 for a sample of the LOOKUP function.)

If any of the arguments to IF are arrays, every element of the array is evaluated when the IF statement is carried out.

Excel provides additional functions that can be used to analyze your data based on a condition. For example, to count the number of occurrences of a string of text or a number within a range of cells, use the COUNTIF or the COUNTIFS worksheet functions. To calculate a sum based on a string of text or a number within a range, use the SUMIF or the SUMIFS worksheet functions. EXAMPLE 1

123

4

5

A B CData50 23Formula Description Result=IF(A2<=100,"Within budget","Over budget")

If the number in cell A2 is less than or equal to 100, the formula returns "Within budget." Otherwise, the function displays "Over budget."

Within budget

=IF(A2=100,A2+B2,"") If the number in cell A2 is equal to 100, A2 + B2 is calculated and returned. Otherwise, empty text ("") is returned.

Empty text ("")

EXAMPLE 212345

6

7

A B CActual Expenses Predicted Expenses1500 900500 900500 925Formula Description Result=IF(A2>B2,"Over Budget","OK")

Checks whether the expenses in row 2 are over budget

Over Budget

=IF(A3>B3,"Over Budget","OK")

Checks whether the expenses in row 3 are over budget

OK

EXAMPLE 3123

A B CScore45

Page 33: Syntax and Purpose of Functions

45

6

7

8

9078Formula Description Resu

lt=IF(A2>89,"A",IF(A2>79,"B", IF(A2>69,"C",IF(A2>59,"D","F"))))

Assigns a letter grade to the score in cell A2

F

=IF(A3>89,"A",IF(A3>79,"B", IF(A3>69,"C",IF(A3>59,"D","F"))))

Assigns a letter grade to the score in cell A3

A

=IF(A4>89,"A",IF(A4>79,"B", IF(A4>69,"C",IF(A4>59,"D","F"))))

Assigns a letter grade to the score in cell A4

C

The preceding example demonstrates how you can nest IF statements. In each formula, the fourth IF statement is also the value_if_false argument to the third IF statement. Similarly, the third IF statement is the value_if_false argument to the second IF statement, and the second IF statement is the value_if_false argument to the first IF statement. For example, if the first logical_test argument (Average>89) evaluates to TRUE, "A" is returned. If the first logical_test argument evaluates to FALSE, the second IF statement is evaluated, and so on. You can also use other functions as arguments.The letter grades are assigned to numbers, using the following key.

If Score isThen return

Greater than 89

A

From 80 to 89

B

From 70 to 79

C

From 60 to 69

D

Less than 60 F

12345

6

7

8

A B CScore459078Formula Description Resu

lt=LOOKUP(A2,{0,60,63,67,70,73,77,80,83,87,90,93,97},{"F","D-","D","D+","C-","C","C+","B-","B","B+","A-","A","A+"})

Assigns a letter grade to the score in cell A2

F

=LOOKUP(A3,{0,60,63,67,70,73,77,80,83,87,90,93,97},{"F","D-","D","D+","C-","C","C+","B-","B","B+","A-","A","A+"})

Assigns a letter grade to the score in cell A3

A-

=LOOKUP(A4,{0,60,63,67,70,73,77,80,83,87,90,93,97},{"F","D-","D","D+","C-","C","C+","B-","B","B+","A-","A","A+"})

Assigns a letter grade to the score in cell A4

ii. AND

Returns TRUE if all its arguments evaluate to TRUE; returns FALSE if one or more arguments evaluate to FALSE.One common use for the AND function is to expand the usefulness of other functions that perform logical tests. For example, the IF function performs a logical test and then returns one value if the test evaluates to

Page 34: Syntax and Purpose of Functions

TRUE and another value if the test evaluates to FALSE. By using the AND function as the logical_test argument of the IF function, you can test many different conditions instead of just one.

AND(logical1, [logical2], ...)The AND function syntax has the following arguments:

logical1 Required. The first condition that you want to test that can evaluate to either TRUE or FALSE.

logical2, ... Optional. Additional conditions that you want to test that can evaluate to either TRUE or FALSE, up to a maximum of 255 conditions.

The arguments must evaluate to logical values, such as TRUE or FALSE, or the arguments must be arrays or references that contain logical values.

If an array or reference argument contains text or empty cells, those values are ignored. If the specified range contains no logical values, the AND function returns the #VALUE! error value.

Examples1234

A B CFormula Description Resu

lt=AND(TRUE, TRUE) All arguments are TRUE TRUE=AND(TRUE, FALSE)

One argument is FALSE FALSE

=AND(2+2=4, 2+3=5)

All arguments evaluate to TRUE

TRUE

EXAMPLE 21234

5

6

7

A B CData50104Formula Description Result=AND(1<A2, A2<100) Displays TRUE if the number in cell A2 is

between 1 and 100. Otherwise, it displays FALSE.

TRUE

=IF(AND(1<A3, A3<100), A3, "The value is out of range.")

Displays the number in cell A3, if it is between 1 and 100. Otherwise, it displays the message "The value is out of range."

The value is out of range.

=IF(AND(1<A2, A2<100), A2, "The value is out of range.")

Displays the number in cell A2, if it is between 1 and 100. Otherwise, it displays a message.

ORReturns TRUE if any argument is TRUE; returns FALSE if all arguments are FALSE.

SyntaxOR(logical1, [logical2], ...)The OR function syntax has the following arguments:

Logical1, logical2, ... Logical1 is required, subsequent logical values are optional. 1 to 255 conditions you want to test that can be either TRUE or FALSE.

Page 35: Syntax and Purpose of Functions

RemarksThe arguments must evaluate to logical values such as TRUE or FALSE, or in arrays or references

that contain logical values. If an array or reference argument contains text or empty cells, those values are ignored. If the specified range contains no logical values, OR returns the #VALUE! error value. You can use an OR array formula to see if a value occurs in an array. To enter an array formula,

press CTRL+SHIFT+ENTER.

Example1234

A BFormula Description (Result)=OR(TRUE) One argument is TRUE (TRUE)=OR(1+1=1,2+2=5)

All arguments evaluate to FALSE (FALSE)

=OR(TRUE,FALSE,TRUE)

At least one argument is TRUE (TRUE)

NOT

Reverses the value of its argument. Use NOT when you want to make sure a value is not equal to one particular value.

SyntaxNOT(logical)The NOT function syntax has the following arguments:

Logical Required. A value or expression that can be evaluated to TRUE or FALSE.

RemarkIf logical is FALSE, NOT returns TRUE; if logical is TRUE, NOT returns FALSE.

Example123

A BFormula Description (Result)=NOT(FALSE)

Reverses FALSE (TRUE)

=NOT(1+1=2)

Reverses an equation that evaluates to TRUE (FALSE)

Date and Time Functions DATE

The DATE function returns the sequential serial number that represents a particular date. For example, the formula=DATE(2008,7,8)returns 39637, the serial number that represents 7/8/2008.

Page 36: Syntax and Purpose of Functions

NOTE If the cell format was General before the function was entered, the result is formatted as a date instead of a number. If you want to view the serial number, or if you want to change the formatting of the date, select a different number format in the Number group of the Home tab.The DATE function is most useful in situations where the year, month, and day are supplied by formulas or cell references. For example, you might have a worksheet that contains dates in a format that Excel does not recognize, such as YYYYMMDD. You can use the DATE function in conjunction with other functions to convert the dates to a serial number that Excel recognizes. See the table in the Example section of this article for more information.

SyntaxDATE(year,month,day)The DATE function syntax has the following arguments:

Year Required. The value of the year argument can include one to four digits. Excel interprets the year argument according to the date system your computer is using. By default, Microsoft Excel for Windows uses the 1900 date system; Microsoft Excel for the Macintosh uses the 1904 date system. TIP We recommend using four digits for the year argument to prevent unwanted results. For example, using "07" returns "1907" as the year value.

If year is between 0 (zero) and 1899 (inclusive), Excel adds that value to 1900 to calculate the year. For example, DATE(108,1,2)returns January 2, 2008 (1900+108).

If year is between 1900 and 9999 (inclusive), Excel uses that value as the year. For example, DATE(2008,1,2)returns January 2, 2008.

If year is less than 0 or is 10000 or greater, Excel returns the #NUM! error value.Month Required. A positive or negative integer representing the month of the year from 1 to 12

(January to December). If month is greater than 12, month adds that number of months to the first month in the

year specified. For example, DATE(2008,14,2)returns the serial number representing February 2, 2009.

If month is less than 1, month subtracts the magnitude of that number of months, plus 1, from the first month in the year specified. For example, DATE(2008,-3,2)returns the serial number representing September 2, 2007.

Day Required. A positive or negative integer representing the day of the month from 1 to 31. If day is greater than the number of days in the month specified, day adds that number of

days to the first day in the month. For example, DATE(2008,1,35)returns the serial number representing February 4, 2008.

If day is less than 1, day subtracts the magnitude that number of days, plus one, from the first day of the month specified. For example, DATE(2008,1,-15)returns the serial number representing December 16, 2007.NOTE Excel stores dates as sequential serial numbers so that they can be used in calculations. By default, January 1, 1900 is serial number 1, and January 1, 2008 is serial number 39448 because it is 39,447 days after January 1, 1900. Microsoft Excel for the Macintosh uses a different date system as its default.

Example12356

A B CYear Month Day2008 1 1Data20081125

Page 37: Syntax and Purpose of Functions

7

8

9

Formula Description Result=DATE(A2,B2,C2) Serial date for the date

derived by using cells A2, B2, and C2 as the arguments for the DATE function, and using the 1900 date system.

1/1/2008 or 39448

=DATE(YEAR(TODAY()),12,31)

Serial date for the last day of the current year.

12/31/nnnn or the equivalent sequential serial number (actual value depends on current year)

=DATE(LEFT(A4,4),MID(A4,5,2), RIGHT(A4,2))

A formula that converts a date from the YYYYMMDD format to a serial date.

11/25/2008 or 39777

NOTE To view the number as a serial number, select the cell and then, on the Home tab, in the Number group, click the arrow next to Number Format, and then click Number.

Today

Returns the serial number of the current date. The serial number is the date-time code used by Excel for date and time calculations. If the cell format was General before the function was entered, Excel changes the cell format to Date. If you want to view the serial number, you must change the cell format to General or Number.The TODAY function is useful when you need to have the current date displayed on a worksheet, regardless of when you open the workbook. It is also useful for calculating intervals. For example, if you know that someone was born in 1963, you might use the following formula to find that person's age as of this year's birthday:=YEAR(TODAY())-1963This formula uses the TODAY function as an argument for the YEAR function to obtain the current year, and then subtracts 1963, returning the person's age.NOTE If the TODAY function does not update the date when you expect it to, you might need to change the settings that control when the workbook or worksheet recalculates. On the File tab, click Options, and then in the Formulas category under Calculation options, make sure that Automatic is selected.

SyntaxTODAY()The TODAY function syntax has no arguments.NOTE Excel stores dates as sequential serial numbers so they can be used in calculations. By default, January 1, 1900 is serial number 1, and January 1, 2008 is serial number 39448 because it is 39,447 days after January 1, 1900. Microsoft Excel for the Macintosh uses a different date system as its default.

Example12

3

45

A BFormula Description=TODAY() Returns the current date.=TODAY()+5 Returns the current date plus 5 days. For example, if the

current date is 1/1/2008, this formula returns 1/6/2008.=DATEVALUE("1/1/2030")-TODAY()

Returns the number of days between the current date and 1/1/2030. Note that cell A4 must be formatted as General or Number for the result to display correctly.

=DAY(TODAY()) Returns the current day of the month (1 - 31).=MONTH(TODAY()) Returns the current month of the year (1 - 12). For example, if

the current month is May, this formula returns 5.

Page 38: Syntax and Purpose of Functions

6

DAYReturns the day of a date, represented by a serial number. The day is given as an integer ranging from 1 to 31.DAY(serial_number)The DAY function syntax has the following arguments:

Serial_number Required. The date of the day you are trying to find. Dates should be entered by using the DATE function, or as results of other formulas or functions. For example, use DATE(2008,5,23) for the 23rd day of May, 2008. Problems can occur if dates are entered as text.

Example1234

A BDate15-Apr-2008Formula Description (Result)=DAY(A2) Day of the date above

(15)

Month

Returns the month of a date represented by a serial number. The month is given as an integer, ranging from 1 (January) to 12 (December).

SyntaxMONTH(serial_number)The MONTH function syntax has the following arguments:

Serial_number Required. The date of the month you are trying to find. Dates should be entered by using the DATE function, or as results of other formulas or functions. For example, use DATE(2008,5,23) for the 23rd day of May, 2008. Problems can occur if dates are entered as text.

Example.

1234

A BDate15-Apr-2008Formula Description (Result)=MONTH(A2)

Month of the date above (4)

Year

Returns the year corresponding to a date. The year is returned as an integer in the range 1900-9999.

SyntaxYEAR(serial_number)The YEAR function syntax has the following arguments:

Page 39: Syntax and Purpose of Functions

Serial_number Required. The date of the year you want to find. Dates should be entered by using the DATE function, or as results of other formulas or functions. For example, use DATE(2008,5,23) for the 23rd day of May, 2008. Problems can occur if dates are entered as text..

123456

A BDate7/5/20087/5/10Formula Description (Result)=YEAR(A2)

Year of the first date (2008)

=YEAR(A3)

Year of the second date (2010)

NowReturns the serial number of the current date and time. If the cell format was General before the function was entered, Excel changes the cell format to the same date and time format that is specified in the regional date and time settings in Control Panel. You can change the date and time format for the cell by using the commands in the Number group of the Home tab on the Ribbon.The NOW function is useful when you need to display the current date and time on a worksheet or calculate a value based on the current date and time, and have that value updated each time you open the worksheet.NOTE If the NOW function does not update cell values when you expect it to, you might need to change settings that control when the workbook or worksheet recalculates.

SyntaxNOW()The NOW function syntax has no arguments.

Time

Returns the decimal number for a particular time. If the cell format was General before the function was entered, the result is formatted as a date.The decimal number returned by TIME is a value ranging from 0 (zero) to 0.99999999, representing the times from 0:00:00 (12:00:00 AM) to 23:59:59 (11:59:59 P.M.).

SyntaxTIME(hour, minute, second)The TIME function syntax has the following arguments:

Hour Required. A number from 0 (zero) to 32767 representing the hour. Any value greater than 23 will be divided by 24 and the remainder will be treated as the hour value. For example, TIME(27,0,0) = TIME(3,0,0) = .125 or 3:00 AM. Minute Required. A number from 0 to 32767 representing the minute. Any value greater than 59 will be converted to hours and minutes. For example, TIME(0,750,0) = TIME(12,30,0) = .520833 or 12:30 PM. Second Required. A number from 0 to 32767 representing the second. Any value greater than 59 will be converted to hours, minutes, and seconds. For example, TIME(0,0,2000) = TIME(0,33,22) = .023148 or 12:33:20 AM

Remark

Page 40: Syntax and Purpose of Functions

Microsoft Excel for Windows and Microsoft Excel for the Macintosh use different date systems as their default. Time values are a portion of a date value and represented by a decimal number (for example, 12:00 PM is represented as 0.5 because it is half of a day).

1234

5

6

A B CHour Minute Secon

d12 0 016 48 10Formula Description (Result)=TIME(A2,B2,C2)

Decimal part of a day, for the first time above (0.5)

=TIME(A3,B3,C3)

Decimal part of a day, for the second time above (0.700115741)

Hour

Returns the hour of a time value. The hour is given as an integer, ranging from 0 (12:00 A.M.) to 23 (11:00 P.M.).

SyntaxHOUR(serial_number)The HOUR function syntax has the following arguments:

Serial_number Required. The time that contains the hour you want to find. Times may be entered as text strings within quotation marks (for example, "6:45 PM"), as decimal numbers (for example, 0.78125, which represents 6:45 PM), or as results of other formulas or functions (for example, TIMEVALUE("6:45 PM")).

RemarkMicrosoft Excel for Windows and Excel for the Macintosh use different date systems as their defaults. Time values are a portion of a date value and represented by a decimal number (for example, 12:00 PM is represented as 0.5 because it is half of a day).

12345678

A BTime3:30:30 AM3:30:30 PM15:30Formula Description

(Result)=HOUR(A2)

Hour of first time (3)

=HOUR(A3)

Hour of second time (15)

=HOUR(A4)

Hour of third time (15)

Page 41: Syntax and Purpose of Functions

MinuteReturns the minutes of a time value. The minute is given as an integer, ranging from 0 to 59.

SyntaxMINUTE(serial_number)The MINUTE function syntax has the following arguments:

Serial_number Required. The time that contains the minute you want to find. Times may be entered as text strings within quotation marks (for example, "6:45 PM"), as decimal numbers (for example, 0.78125, which represents 6:45 PM), or as results of other formulas or functions (for example, TIMEVALUE("6:45 PM")).

1234

A BTime4:48:00 PMFormula Description (Result)=MINUTE(A2)

Minutes of the time above (48)

SecondReturns the seconds of a time value. The second is given as an integer in the range 0 (zero) to 59.SECOND(serial_number)The SECOND function syntax has the following arguments:

Serial_number Required. The time that contains the seconds you want to find. Times may be entered as text strings within quotation marks (for example, "6:45 PM"), as decimal numbers (for example, 0.78125, which represents 6:45 PM), or as results of other formulas or functions (for example, TIMEVALUE("6:45 PM")).

123456

A BTime4:48:18 PM4:48 PMFormula Description=SECOND(A2)

Seconds in the first time (18)

=SECOND(A3)

Seconds in the second time (0)

WeeknumReturns the week number of a specific date. For example, the week containing January 1 is the first week of the year, and is numbered week 1.There are two systems used for this function:

System 1 The week containing January 1 is the first week of the year, and is numbered week 1. System 2 The week containing the first Thursday of the year is the first week of the year, and is numbered as week 1.

WEEKNUM(serial_number,[return_type])The WEEKNUM function syntax has the following arguments:

Serial_number Required. A date within the week. Dates should be entered by using the DATE function, or as results of other formulas or functions. For example, use DATE(2008,5,23) for the 23rd day of May, 2008. Problems can occur if dates are entered as text. Return_type Optional. A number that determines on which day the week begins. The default is 1.

Page 42: Syntax and Purpose of Functions

Return_type

Week begins on

System

1 or omitted Sunday 12 Monday 111 Monday 112 Tuesday 113 Wednesday 114 Thursday 115 Friday 116 Saturday 117 Sunday 121 Monday 2

RemarkMicrosoft Excel stores dates as sequential serial numbers so they can be used in calculations. By default, January 1, 1900 is serial number 1, and January 1, 2008 is serial number 39448 because it is 39,448 days after January 1, 1900. If serial_number is out of range for the current date base value, a #NUM! error is returned. If return_type is out of the range specified in the table above, a #NUM! error is returned.

Example 1123

4

5

A BDataMarch 9, 2008Formula Description (Result)=WEEKNUM(A2,1)

Number of the week in the year, with a week beginning on Sunday (11)

=WEEKNUM(A2,2)

Number of the week in the year, with a week beginning on Monday (10)

NOTE March 9, 2008 is a Sunday.

Example 21

2

3

4

5

A BFormula Description (Result)=WEEKNUM(DATE(2006,1,1))

Number of the week in the year, with a week beginning on Sunday (1)

=WEEKNUM(DATE(2006,1,1),1)

Number of the week in the year, with a week beginning on Sunday (1)

=WEEKNUM(DATE(2006,1,1),17)

Number of the week in the year, with a week beginning on Sunday (1)

=WEEKNUM(DATE(2006,2,1),1)

Number of the week in the year, with a week beginning on Sunday (5)

=WEEKNUM(DATE(2006,2,1),2)

Number of the week in the year, with a week beginning on Monday (6)

=WEEKNUM(DATE(2006,2,1),11)

Number of the week in the year, with a week beginning on Monday (6)

Page 43: Syntax and Purpose of Functions

WeekdayReturns the day of the week corresponding to a date. The day is given as an integer, ranging from 1 (Sunday) to 7 (Saturday), by default.WEEKDAY(serial_number,[return_type])The WEEKDAY function syntax has the following arguments:

Serial_number Required. A sequential number that represents the date of the day you are trying to find. Dates should be entered by using the DATE function, or as results of other formulas or functions. For example, use DATE(2008,5,23) for the 23rd day of May, 2008. Problems can occur if dates are entered as text. Return_type Optional. A number that determines the type of return value. Return_type Number returned1 or omitted

Numbers 1 (Sunday) through 7 (Saturday). Behaves like previous versions of Microsoft Excel.

2 Numbers 1 (Monday) through 7 (Sunday).3 Numbers 0 (Monday) through 6 (Sunday).11 Numbers 1 (Monday) through 7 (Sunday).12 Numbers 1 (Tuesday) through 7 (Monday).13 Numbers 1 (Wednesday) through 7 (Tuesday).14 Numbers 1 (Thursday) through 7 (Wednesday).15 Numbers 1 (Friday) through 7 (Thursday).16 Numbers 1 (Saturday) through 7 (Friday).17 Numbers 1 (Sunday) through 7 (Saturday).

RemarkMicrosoft Excel stores dates as sequential serial numbers so they can be used in calculations. By default, January 1, 1900 is serial number 1, and January 1, 2008 is serial number 39448 because it is 39,448 days after January 1, 1900. If serial_number is out of range for the current date base value, a #NUM! error is returned. If return_type is out of the range specified in the table above, a #NUM! error is returned.

Example123

4

5

6

A BData2/14/2008Formula Description (Result)=WEEKDAY(A2) Day of the week, with numbers 1 (Sunday) through 7

(Saturday) (5)=WEEKDAY(A2, 2)

Day of the week, with numbers 1 (Monday) through 7 (Sunday) (4)

=WEEKDAY(A2, 3)

Day of the week, with numbers 0 (Monday) through 6 (Sunday) (3)

NOTE 2/14/2008 is a Thursday.

Data Base Functions Function DdayescriptionDAVERAGE Returns the average of selected database entries

Page 44: Syntax and Purpose of Functions

functionDCOUNT function Counts the cells that contain numbers in a databaseDCOUNTA function

Counts nonblank cells in a database

DGET function Extracts from a database a single record that matches the specified criteriaDMAX function Returns the maximum value from selected database entriesDMIN function Returns the minimum value from selected database entriesDPRODUCT function

Multiplies the values in a particular field of records that match the criteria in a database

DSTDEV function Estimates the standard deviation based on a sample of selected database entriesDSTDEVP function

Calculates the standard deviation based on the entire population of selected database entries

DSUM function Adds the numbers in the field column of records in the database that match the criteria

DVAR function Estimates variance based on a sample from selected database entriesDVARP function Calculates variance based on the entire population of selected database entries

Dsum

Adds the numbers in a field (column) of records in a list or database that match conditions that you specify.

SyntaxDSUM(database, field, criteria)The DSUM function syntax has the following arguments:

Database Required. The range of cells that makes up the list or database. A database is a list of related data in which rows of related information are records, and columns of data are fields. The first row of the list contains labels for each column. Field Required. Indicates which column is used in the function. Enter the column label enclosed between double quotation marks, such as "Age" or "Yield," or a number (without quotation marks) that represents the position of the column within the list: 1 for the first column, 2 for the second column, and so on. Criteria Required. Is the range of cells that contains the conditions that you specify. You can use any range for the criteria argument, as long as it includes at least one column label and at least one cell below the column label in which you specify a condition for the column.

RemarksYou can use any range for the criteria argument, as long as it includes at least one column label and at least one cell below the column label for specifying the condition. For example, if the range G1:G2 contains the column label Income in G1 and the amount $10,000 in G2, you could define the range as MatchIncome and use that name as the criteria argument in the database functions.Although the criteria range can be located anywhere on the worksheet, do not place the criteria range below the list. If you add more information to the list, the new information is added to the first row below the list. If the row below the list is not blank, Microsoft Excel cannot add the new information. Make sure that the criteria range does not overlap the list. To perform an operation on an entire column in a database, enter a blank line below the column labels in the criteria range.

Examples1. .

1 A B C D E F

Page 45: Syntax and Purpose of Functions

234567891011

12

13

Tree Height Age

Yield

Profit

Height

="=Apple" >10 <16="=Pear"Tree Height Ag

eYield

Profit

Apple 18 20 14 105.00

Pear 12 12 10 96.00Cherry 13 14 9 105.0

0Apple 14 15 10 75.00Pear 9 8 8 76.80Apple 8 9 6 45.00Formula Description (Result)=DSUM(A4:E10, "Profit", A1:A2)

The total profit from apple trees. (225)

=DSUM(A4:E10, "Profit", A1:F2)

The total profit from apple trees with a height between 10 and 16. (75)

CRITERIA EXAMPLESIMPORTANT

Because the equal sign is used to indicate a formula when you type text or a value in a cell, Microsoft Excel evaluates what you type; however, this may cause unexpected filter results. To indicate an equality comparison operator for either text or a value, type the criteria as a string expression in the appropriate cell in the criteria range: =''=entry''Where entry is the text or value you want to find. For example:What you type in the cell

What Excel evaluates and displays

="=Davolio" =Davolio="=3000" =3000When filtering text data, Excel does not distinguish between uppercase and lowercase characters. However, you can use a formula to perform a case-sensitive search. For an example, see Filtering for text by using a case-sensitive search.

The following sections provide examples of complex criteria. Multiple criteria in one columnBoolean logic: (Salesperson = "Davolio" OR Salesperson = "Buchanan")To find rows that meet multiple criteria for one column, type the criteria directly below each other in separate rows of the criteria range. In the following data range (A6:C10), the criteria range (B1:B3) displays the rows that contain either "Davolio" or "Buchanan" in the Salesperson column (A8:C10).

A B C

1 TypeSalesperson

Sales

2 =Davolio

3=Buchanan

45

Page 46: Syntax and Purpose of Functions

6 TypeSalesperson

Sales

7Beverages

Suyama $5122

8 Meat Davolio $450

9produce

Buchanan $6328

10

Produce

Davolio $6544

Multiple criteria in multiple columns where all criteria must be trueBoolean logic: (Type = "Produce" AND Sales > 1000)To find rows that meet multiple criteria in multiple columns, type all of the criteria in the same row of the criteria range. In the following data range (A6:C10), the criteria range (A1:C2) displays all rows that contain "Produce" in the Type column and a value greater than $1,000 in the Sales column (A9:C10).

A B C

1 TypeSalesperson

Sales

2=Produce

>1000

345

6 TypeSalesperson

Sales

7Beverages

Suyama $5122

8 Meat Davolio $450

9produce

Buchanan $6328

10

Produce

Davolio $6544

Multiple criteria in multiple columns where any criteria can be trueBoolean logic: (Type = "Produce" OR Salesperson = "Davolio")To find rows that meet multiple criteria in multiple columns, where any criteria can be true, type the criteria in different rows of the criteria range. In the following data range (A6:C10), the criteria range (A1:B3) displays all rows that contain "Produce" in the Type column or "Davolio" in the Salesperson column (A8:C10).

A B C

1 TypeSalesperson

Sales

2=Produce

3 =Davolio45

6 TypeSalesperson

Sales

7Beverages

Suyama $5122

8 Meat Davolio $450

Page 47: Syntax and Purpose of Functions

9produce

Buchanan $6328

10

Produce

Davolio $6544

Multiple sets of criteria where each set includes criteria for multiple columnsBoolean logic: ( (Salesperson = "Davolio" AND Sales >3000) OR (Salesperson = "Buchanan" AND Sales > 1500) )To find rows that meet multiple sets of criteria, where each set includes criteria for multiple columns, type each set of criteria in separate rows. In the following data range (A6:C10), the criteria range (B1:C3) displays the rows that contain both "Davolio" in the Salesperson column and a value greater than $3,000 in the Sales column, or displays the rows that contain "Buchanan" in the Salesperson and a value greater than $1,500 in the Sales column (A9:C10).

A B C

1 TypeSalesperson

Sales

2=Davolio >300

0

3=Buchanan

>1500

45

6 TypeSalesperson

Sales

7Beverages

Suyama $5122

8 Meat Davolio $450

9produce

Buchanan $6328

10

Produce

Davolio $6544

Multiple sets of criteria where each set includes criteria for one columnBoolean logic: ( (Sales > 6000 AND Sales < 6500 ) OR (Sales < 500) )To find rows that meet multiple sets of criteria, where each set includes criteria for one column, include multiple columns with the same column heading. In the following data range (A6:C10), the criteria range (C1:D3) displays rows that contain values between 6,000 and 6,500 and values less than 500 in the Sales column (A8:C10).

A B C D

1 TypeSalesperson

Sales

Sales

2>6000

<6500

3 <50045

6 TypeSalesperson

Sales

7Beverages

Suyama $5122

8 Meat Davolio $450

9produce

Buchanan $6328

Page 48: Syntax and Purpose of Functions

10

Produce Davolio $6544

Criteria to find text values that share some characters but not othersTo find text values that share some characters but not others, do one or more of the following:

Type one or more characters without an equal sign (=) to find rows with a text value in a column that begin with those characters. For example, if you type the text Dav as a criterion, Excel finds "Davolio," "David," and "Davis." Use a wildcard character. The following wildcard characters can be used as comparison criteria.Use To find? (question mark) Any single character

For example, sm?th finds "smith" and "smyth"* (asterisk) Any number of characters

For example, *east finds "Northeast" and "Southeast"

~ (tilde) followed by ?, *, or ~

A question mark, asterisk, or tildeFor example, fy91~? finds "fy91?"

In the following data range (A6:C10), the criteria range (A1:B3) displays rows with "Me" as the first characters in the Type column or rows with the second character equal to "u" in the Salesperson column (A7:C9).

A B C

1 TypeSalesperson

Sales

2 Me3 =?u*45

6 TypeSalesperson

Sales

7Beverages

Suyama $5122

8 Meat Davolio $450

9produce Buchanan $632

810

Produce Davolio $6544

Criteria created as the result of a formulaYou can use a calculated value that is the result of a formula as your criterion. Remember the following important points:

The formula must evaluate to TRUE or FALSE. Because you are using a formula, enter the formula as you normally would, and do not type the expression in the following way: =''=entry''Do not use a column label for criteria labels; either keep the criteria labels blank or use a label that is not a column label in the range (in the examples below, Calculated Average and Exact Match). If you use a column label in the formula instead of a relative cell reference or a range name, Excel displays an error value such as #NAME? or #VALUE! in the cell that contains the criterion. You can ignore this error because it does not affect how the range is filtered.The formula that you use for criteria must use a relative reference to refer to the corresponding cell in the first row (in the examples below, C7 and A7). All other references in the formula must be absolute references.

The following subsections provide specific examples of criteria created as the result of a formula. FILTERING FOR VALUES GREATER THAN THE AVERAGE OF ALL VALUES IN THE DATA RANGE

Page 49: Syntax and Purpose of Functions

In the following data range (A6:D10), the criteria range (D1:D2) displays rows that have a value in the Sales column greater than the average of all the Sales values (C7:C10). In the formula, "C7" refers to the filtered column (C) of the first row of the data range (7).

A B C D

1 TypeSalesperson

Sales Calculated Average

2=C7>AVERAGE($C$7:$C$10)

345

6 TypeSalesperson

Sales

7Beverages

Suyama $5122

8 Meat Davolio $450

9produce Buchanan $632

810

Produce Davolio $6544

FILTERING FOR TEXT BY USING A CASE-SENSITIVE SEARCH In the data range (A6:D10), the criteria range (D1:D2) displays rows that contain "Produce" in the Type column by using the EXACT function to perform a case-sensitive search (A10:C10). In the formula, "A7" refers to the filtered column (A) of the first row of the data range (7).

A B C D

1 TypeSalesperson

Sales Exact Match

2=EXACT(A7,

"Produce")345

6 TypeSalesperson

Sales

7Beverages

Suyama $5122

8 Meat Davolio $450

9produce Buchanan $632

810

Produce

Davolio $6544

Information function

Page 50: Syntax and Purpose of Functions

Each of these functions, referred to collectively as the IS functions, checks the specified value and returns

TRUE or FALSE depending on the outcome. For example, the ISBLANK function returns the logical value

TRUE if the value argument is a reference to an empty cell; otherwise it returns FALSE.

You can use an IS function to get information about a value before performing a calculation or other action with

it. For example, you can use the ISERROR function in conjunction with the IF function to perform a different

action if an error occurs:

=IF(ISERROR(A1), "An error occurred.", A1 * 2)

This formula checks to see if an error condition exists in A1. If so, the IF function returns the message "An error

occurred." If no error exists, the IF function performs the calculation A1*2.

Syntax

ISBLANK(value)

ISERR(value)

ISERROR(value)

ISLOGICAL(value)

ISNA(value)

ISNONTEXT(value)

ISNUMBER(value)

ISREF(value)

ISTEXT(value)

The IS function syntax has the following argument:

value Required. The value that you want tested. The value argument can be a blank (empty cell),

error, logical value, text, number, or reference value, or a name referring to any of these.

Function Returns TRUE if

ISBLANK Value refers to an empty cell.

ISERR Value refers to any error value except #N/A.

ISERROR Value refers to any error value (#N/A, #VALUE!, #REF!, #DIV/0!, #NUM!, #NAME?, or #NULL!).

Page 51: Syntax and Purpose of Functions

ISLOGICAL

Value refers to a logical value.

ISNA Value refers to the #N/A (value not available) error value.

ISNONTEXT

Value refers to any item that is not text. (Note that this function returns TRUE if the value refers to a blank cell.)

ISNUMBER

Value refers to a number.

ISREF Value refers to a reference.

ISTEXT Value refers to text.

Remarks

The value arguments of the IS functions are not converted. Any numeric values that are enclosed in

double quotation marks are treated as text. For example, in most other functions where a number is

required, the text value "19" is converted to the number 19. However, in the formula

ISNUMBER("19"), "19" is not converted from a text value to a number value, and the ISNUMBER

function returns FALSE.

The IS functions are useful in formulas for testing the outcome of a calculation. When combined with

the IF function, these functions provide a method for locating errors in formulas (see the following

examples).

Example

EXAMPLE 11

2

3

4

5

6

A B C

Formula Description Result

=ISLOGICAL(TRUE)

Checks whether TRUE is a logical value

TRUE

=ISLOGICAL("TRUE")

Checks whether "TRUE" is a logical value

FALSE

=ISNUMBER(4) Checks whether 4 is a number TRUE

=ISREF(G8) Checks whether G8 is a valid reference

TRUE

=ISREF(XYZ1) Checks whether XYZ1 is a valid reference

FALSE

Page 52: Syntax and Purpose of Functions

EXAMPLE 2

1

2

3

4

5

6

7

8

9

10

11

12

13

14

A B C

Data

Gold

Region1

#REF!

330.92

#N/A

Formula Description Result

=ISBLANK(A2) Checks whether cell A2 is blank. FALSE

=ISERROR(A4)

Checks whether the value in cell A4, #REF!, is an error.

TRUE

=ISNA(A4) Checks whether the value in cell A4, #REF!, is the #N/A error.

FALSE

=ISNA(A6) Checks whether the value in cell A6, #N/A, is the #N/A error.

TRUE

=ISERR(A6) Checks whether the value in cell A6, #N/A, is an error.

FALSE

=ISNUMBER(A5)

Checks whether the value in cell A5, 330.92, is a number.

TRUE

=ISTEXT(A3) Checks whether the value in cell A3, Region1, is text.

TRUE


Recommended