Professional Documents
Culture Documents
Excel Formulas
Excel Formulas
Excel Formulas
Formulas
NOTE: This page is no longer updated. Most of the topics here are now covered on other pages, or have pages of their own. However, I will leave this page intact and available. See the Topics Index page for a complete list of topics covered on my web site.
Array Formulas
Many of the formulas described here are Array Formulas, which are a special type of formula in Excel. If you are not familiar with Array Formulas, click here.
Array To Column
Sometimes it is useful to convert an MxN array into a single column of data, for example for charting (a data series must be a single row or column). Click here for more details.
4/17/2014
Excel Formulas
5 and 10, use the following array formula: = S U M ( ( A 1 : A 1 0 > = 5 ) * ( A 1 : A 1 0 < = 1 0 ) ) To sum the same numbers, use the following array formula: = S U M ( ( A 1 : A 1 0 > = 5 ) * ( A 1 : A 1 0 < = 1 0 ) * A 1 : A 1 0 )
Dynamic Ranges
You can define a name to refer to a range whose size varies depending on its contents. For example, you may want a range name that refers only to the portion of a list of numbers that are not blank. such as only the first Nnon-blank cells in A 2 : A 2 0 . Define a name called MyRange, and set the Refers To property to: = O F F S E T ( S h e e t 1 ! $ A $ 2 , 0 , 0 , C O U N T A ( $ A $ 2 : $ A $ 2 0 ) , 1 ) Be sure to use absolute cell references in the formula. Also see then Named Ranges page for more information about dynamic ranges.
4/17/2014
Excel Formulas
Suppose we've got a range of data called D a t a R a n g e 2 , defined as H 7 : I 2 5 , and that cells H 7 : I 1 7actually contain values. The rest are blank. We can find various properties of the range, as follows: To find the range that contains data, use the following array formula: = A D D R E S S ( R O W ( D a t a R a n g e 2 ) , C O L U M N ( D a t a R a n g e 2 ) , 4 ) & " : " & A D D R E S S ( M A X ( ( D a t a R a n g e 2 < > " " ) * R O W ( D a t a R a n g e 2 ) ) , C O L U M N ( D a t a R a n g e 2 ) + C O L U M N S ( D a t a R a n g e 2 ) 1 , 4 ) This will return the range H 7 : I 1 7 . If you need the worksheet name in the returned range, use the following array formula: = A D D R E S S ( R O W ( D a t a R a n g e 2 ) , C O L U M N ( D a t a R a n g e 2 ) , 4 , , " M y S h e e t " ) & " : " & A D D R E S S ( M A X ( ( D a t a R a n g e 2 < > " " ) * R O W ( D a t a R a n g e 2 ) ) , C O L U M N ( D a t a R a n g e 2 ) + C O L U M N S ( D a t a R a n g e 2 ) 1 , 4 ) This will return M y S h e e t ! H 7 : I 1 7 . To find the number of rows that contain data, use the following array formula: = ( M A X ( ( D a t a R a n g e 2 < > " " ) * R O W ( D a t a R a n g e 2 ) ) ) R O W ( D a t a R a n g e 2 ) + 1 This will return the number 11, indicating that the first 11 rows of D a t a R a n g e 2contain data. To find the last entry in the first column of D a t a R a n g e 2 , use the following array formula: = I N D I R E C T ( A D D R E S S ( M A X ( ( D a t a R a n g e 2 < > " " ) * R O W ( D a t a R a n g e 2 ) ) , C O L U M N ( D a t a R a n g e 2 ) , 4 ) ) To find the last entry in the second column of D a t a R a n g e 2 , use the following array formula: = I N D I R E C T ( A D D R E S S ( M A X ( ( D a t a R a n g e 2 < > " " ) * R O W ( D a t a R a n g e 2 ) ) , C O L U M N ( D a t a R a n g e 2 ) + 1 , 4 ) )
4/17/2014
Excel Formulas
We can extend these ideas to the following. Suppose A 1contains the string "F i r s t S e c o n d T h i r dL a s t ".
Grades
http://www.cpearson.com/excel/excelf.htm 4/8
4/17/2014
Excel Formulas
A frequent question is how to assign a letter grade to a numeric value. This is simple. First create a define name called "Grades" which refers to the array: = { 0 , " F " ; 6 0 , " D " ; 7 0 , " C " ; 8 0 , " B " ; 9 0 , " A " } Then, use VLOOKUP to convert the number to the grade: = V L O O K U P ( A 1 , G r a d e s , 2 ) where A1 is the cell contains the numeric value. You can add entries to the Grades array for other grades like C- and C+. Just make sure the numeric values in the array are in increasing order.
Left Lookups
The easiest way do table lookups is with the = V L O O K U Pfunction. However, = V L O O K U Prequires that the value returned be to the right of the value you're looking up. For example, if you're looking up a value in column B, you cannot retrieve values in column A. If you need to retrieve a value in a column to the left of the column containing the lookup value, use either of the following formulas: = I N D I R E C T ( A D D R E S S ( R O W ( R n g ) + M A T C H ( C 1 , R n g , 0 ) 1 , C O L U M N ( R n g ) C o l s T o L e f t ) ) Or = I N D I R E C T ( A D D R E S S ( R O W ( R n g ) + M A T C H ( C 1 , R n g , 0 ) 1 , C O L U M N ( A : A )) ) Where R n gis the range containing the lookup values, and C o l s T o L e f tis the number of columns to the left of R n gthat the retrieval values are. In the second syntax, replace "A : A " with the column containing the retrieval data. In both examples, C 1is the value you want to look up. See the Lookups page for many more examples of lookup formulas.
http://www.cpearson.com/excel/excelf.htm
5/8
4/17/2014
Excel Formulas
4/17/2014
Excel Formulas
Ranking Numbers
Often, it is useful to be able to return the Nhighest or lowest values from a range of data. Suppose we have a range of numeric data called R a n k R n g . Create a range next to R a n k R n g(starting in the same row, with the same number of rows) called T o p R n g . Also, create a named cell called T o p N , and enter into it the number of values you want to return (e.g., 5 for the top 5 values in R a n k R n g ). Enter the following formula in the first cell in T o p R n g , and use Fill Down to fill out the range: = I F ( R O W ( ) R O W ( T o p R n g ) + 1 > T o p N , " " , L A R G E ( R a n k R n g , R O W ( ) R O W ( T o p R n g ) + 1 ) ) To return the T o p Nsmallest values of R a n k R n g , use = I F ( R O W ( ) R O W ( T o p R n g ) + 1 > T o p N , " " , S M A L L ( R a n k R n g , R O W ( ) R O W ( T o p R n g ) + 1 ) ) The list of numbers returned by these functions will automatically change as you change the contents of R a n k R n gor T o p N . Download a workbook illustrating these formulas. See the Ranking page for much more information about ranking numbers in Excel.
http://www.cpearson.com/excel/excelf.htm
7/8
4/17/2014
Excel Formulas
Miscellaneous
Sheet Name
Suppose our active sheet is named "M y S h e e t " in the file C : \ F i l e s \ M y B o o k . X l s . To return the full sheet name (including the file path) to a cell, use = C E L L ( " f i l e n a m e " , A 1 ) Note that the argument to the = C E L Lfunction is the word " f i l e n a m e "in quotes, not your actual filename. This will return "C : \ F i l e s \ [ M y B o o k . x l s ] M y S h e e t " To return the sheet name, without the path, use = M I D ( C E L L ( " f i l e n a m e " , A 1 ) , F I N D ( " ] " , C E L L ( " f i l e n a m e " , A 1 ) ) + 1 , L E N ( C E L L ( " f i l e n a m e " , A 1 ) ) F I N D ( " ] " , C E L L ( " f i l e n a m e " , A 1 ) ) ) This will return "M y S h e e t "
File Name
Suppose our active sheet is named "MySheet" in the file C:\Files\MyBook.Xls. To return the file name without the path, use = M I D ( C E L L ( " f i l e n a m e " , A 1 ) , F I N D ( " [ " , C E L L ( " f i l e n a m e " , A 1 ) ) + 1 , F I N D ( " ] " , C E L L ( " f i l e n a m e " , A 1 ) ) F I N D ( " [ " , C E L L ( " f i l e n a m e " , A 1 ) ) 1 ) This will return "M y B o o k . x l s " To return the file name with the path, use either = L E F T ( C E L L ( " f i l e n a m e " , A 1 ) , F I N D ( " ] " , C E L L ( " f i l e n a m e " , A 1 ) ) ) Or = S U B S T I T U T E ( S U B S T I T U T E ( L E F T ( C E L L ( " f i l e n a m e " , A 1 ) , F I N D ( " ] " , C E L L ( " f i l e n a m e " , A 1 ) ) ) , " [ " , " " ) , " ] " , " " ) The first syntax will return "C : \ F i l e s \ [ M y B o o k . x l s ] " The second syntax will return "C : \ F i l e s \ M y B o o k . x l s " In all of the examples above, the A 1argument to the = C E L Lfunction forces Excel to get the sheet name from the sheet containing the formula. Without it, and Excel calculates the = C E L Lfunction when another sheet is active, the cell would contain the name of the active sheet, not the sheet actually containing the formula. Download a workbook illustrating these formulas.
http://www.cpearson.com/excel/excelf.htm
8/8