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

Averaging Values In A Range
You can use Excel's built in =AVERAGE function to average a range of values. By using it with other functions, you can extend its functionality. For the formulas given below, assume that our data is in the range A1:A60.

Averaging Values Between Two Numbers
Use the array formula =AVERAGE(IF((A1:A60>=Low)*(A1:A60<=High),A1:A60)) Where Low and High are the values between which you want to average.

Averaging The Highest N Numbers In A Range
To average the N largest numbers in a range, use the array formula =AVERAGE(LARGE(A1:A60,ROW(INDIRECT("1:10")))) Change "1:10" to "1:N" where N is the number of values to average.

Averaging The Lowest N Numbers In A Range
To average the N smallest numbers in a range, use the array formula =AVERAGE(SMALL(A1:A60,ROW(INDIRECT("1:10")))) Change "1:10" to "1:N" where N is the number of values to average. In all of the formulas above, you can use =SUM instead of =AVERAGE to sum, rather than average, the numbers.

Counting Values Between Two Numbers
If you need to count the values in a range that are between two numbers, for example between 5 and 10, use the following array formula: =SUM((A1:A10>=5)*(A1:A10<=10)) To sum the same numbers, use the following array formula:

. use the following array formula: =ADDRESS(ROW(DataRange2). you may want a range name that refers only to the portion of a list of numbers that are not blank.1) Be sure to use absolute cell references in the formula. Finding The Used Part Of A Range Suppose we've got a range of data called DataRange2. Also see then Named Ranges page for more information about dynamic ranges."b". such as only the first N non-blank cells in A2:A20.COLUMN(DataRange2). The rest are blank."B".0. These procedures are described in Duplicates. We can find various properties of the range."")) Date And Time Formulas A variety of formulas useful when working with dates and times are described on the DateTime page. Dynamic Ranges You can define a name to refer to a range whose size varies depending on its contents.0. =LEN(B1)-LEN(SUBSTITUTE(SUBSTITUTE(B1. defined as H7:I25. Define a name called MyRange.""). both upper and lower case. and set the Refers To property to: =OFFSET(Sheet1!$A$2. in the string in B1. Adding Months And Years The DATEDIF Function Date Intervals Dates And Times Date And Time Entry Holidays Julian Dates Duplicate And Unique Values In A Range The task of finding duplicate or unique values in a range of data requires some complicated formulas.4) This will return the range H7:I17. as follows: To find the range that contains data. and that cells H7:I17 actually contain values.COLUMN(DataRange2)+ COLUMNS(DataRange2)-1. For example.COUNTA($A$2:$A$20).4)&":"& ADDRESS(MAX((DataRange2<>"")*ROW(DataRange2)). Other Date Related Procedures are described on the following pages. If you need the worksheet name in the returned range.=SUM((A1:A10>=5)*(A1:A10<=10)*A1:A10) Counting Characters In A String The following formula will count the number of "B"s.

There are several formulas that will break the names apart into first and last names separately. use the following array formula: =INDIRECT(ADDRESS(MAX((DataRange2<>"")*ROW(DataRange2)). including the middle name (if present). To return the last name.""))))) To return the first name.. without the middle name (if present).ROW(INDIRECT("1:"&LEN(A1))). use =LEFT(B2.FIND(" ".LEN(A2)-FIND("*".use the following array formula: =ADDRESS(ROW(DataRange2).FIND(" ".FIND("*"."*".COLUMN(DataRange2). To find the number of rows that contain data.4) This will return MySheet!H7:I17.SUBSTITUTE(A2. use the following array formula: =(MAX((DataRange2<>"")*ROW(DataRange2)))-ROW(DataRange2)+1 This will return the number 11.A1. Suppose cell A2 contains the name "John A Smith". COLUMN(DataRange2)." ". COLUMN(DataRange2)+1.B2. use =LEFT(A2.SUBSTITUTE(A2.LEN(A1)-MAX(ROW(INDIRECT("1:"&LEN(A1))) *(MID(A1. . indicating that the first 11 rows of DataRange2 contain data." ". use the following array formula: =INDIRECT(ADDRESS(MAX((DataRange2<>"")*ROW(DataRange2)).4)) To find the last entry in the second column of DataRange2.4.1)=" "))) This formula in as array formula.1)) We can extend these ideas to the following. To find the last entry in the first column of DataRange2.LEN(A2)LEN(SUBSTITUTE(A2."*"."MySheet")&":"& ADDRESS(MAX((DataRange2<>"")*ROW(DataRange2)).COLUMN(DataRange2)+ COLUMNS(DataRange2)-1.LEN(A2)LEN(SUBSTITUTE(A2.1)) This will return the word "First". Returning Last Word In A String =RIGHT(A1. Returning First Word In A String =LEFT(A1. use =RIGHT(A2." "." ". Suppose A1 contains the string "First Second Third Last".4)) First And Last Names Suppose you've got a range of data consisting of people's first and last names.""))))-1) To return the first name.

click on the Calculation tab.1} are enclosed in array braces (curly brackets {} ) not parentheses.1)=" B10). to get. You can add entries to the Grades array for other grades like C. B10 is the number of the word to get.g. High And Low Values You can use Excel's Circular Reference tool to have a cell that contains the highest ever reached value. and C10 is the number of words. starting at B10. You can set up a cell that will contain the highest score ever reached. Just make sure the numeric values in the array are in increasing order.SMALL(IF(MID(" ("1:"&LEN(A10)+1)).(This formula comes from Laurent Longre). the {0.1)) This will return the words "Second Third Last" Returning Any Word Or Words In A String The following two array formulas come compliments of Laurent Longre.SMALL(IF(MID(" "&A10.1})*{-1. Where A10 is the cell containing the text. 6th.ROW(INDIRECT ". Grades A frequent question is how to assign a letter grade to a numeric value. B10).ROW(INDIRECT("1:"&LEN(A10)+2))).SUM(SMALL(IF(MID(" "&A10&" ". or the 5th.70. This is simple.ROW(INDIRECT("1:"&LEN(A10)+1))). This formula can be extended to get any set of words in the string.2) where A1 is the cell contains the numeric value. suppose you have a worksheet used to track team scores.ROW(INDIRECT("1:"&LEN(A10)+2))).1})*{-1. Download a workbook illustrating these formulas.1})-1) Where A10 is the cell containg the text.1)=" B10+{0. and check the Interations check box. Note that in the above array formulas. use the following array formula: =MID(A10.ROW(INDIRECT("1:"&LEN(A10)+1))).ROW(INDIRECT ".A1. First."D".80."B". even if that score is deleted from the list. Then.1})-1) "&A10.Grades.1} and {-1. First create a define name called "Grades" which refers to the array: ={0.ROW(INDIRECT ("1:"&LEN(A10)+2))."F". B10+C10*{0.SUM(SMALL(IF(MID(" ("1:"&LEN(A10)+2)). the 5th word for 3. For example. use VLOOKUP to convert the number to the grade: =VLOOKUP(A1.LEN(A1)-FIND(" ". enter the following formula in cell B1: ."C".ROW(INDIRECT ("1:"&LEN(A10)+1))."A"} Then. "&A10&" ". To get the words from M for N words (e. and B10 is the number of the word you want to get.90. To return any single word from a single-spaced string of words. This will return the word "Last" Returning All But First Word In A String =RIGHT(A1.1)=" ". and 7th words). use the following array formula: =MID(A10. Suppose the score are in A1:A10..and C+.1)=" ".60. go to the Tools->Options dialog.

the address of the first '1' in the range.0)-1. In both examples. Another method to do this. and ColsToLeft is the number of columns to the left of Rng that the retrieval values are.Rng. even if that value is deleted from the range.COLUMN(NumRange). Left Lookups The easiest way do table lookups is with the =VLOOKUP function. you cannot retrieve values in column A. is provided by Laurent Longre. and uses the CALL function to access the Excel4 macro function library.COLUMN(A:A) )) Where Rng is the range containing the lookup values. the address of the last '1' in the range. In the second syntax.ROW(NumRange)*(NumRange<>""))). Suppose we've got a range of numeric values called NumRange.COLUMN(Rng)-ColsToLeft)) Or =INDIRECT(ADDRESS(ROW(Rng)+MATCH(C1. See the Lookups page for many more examples of lookup formulas. If you need to retrieve a value in a column to the left of the column containing the lookup value. Use the =MIN function to get the lowest ever value. .=MAX(A1:A10. Address Of The Last Minimum In A Range To return the address of the cell containing the last (or only) instance of the minimum of a list. use either of the following formulas: =INDIRECT(ADDRESS(ROW(Rng)+MATCH(C1. COLUMN(NumRange).ROW(NumRange))). without using circular references. =VLOOKUP requires that the value returned be to the right of the value you're looking up.Rng. use the following array formula: =ADDRESS(MIN(IF(NumRange=MIN(NumRange).0)-1. Minimum And Maximum Values In A Range Of course you can use the =MIN and =MAX functions to return the minimum and maximum values of a range. For example. C1 is the value you want to look up.B1) Cell B1 will contian the highest value that has ever been present in A1:A10.4) This function returns B2. NumRange may contain duplicate values. Click here for details. use the following array formula: =ADDRESS(MAX(IF(NumRange=MIN(NumRange).4) This function returns B4. The formulas below use the following example: Address Of First Minimum In A Range To return the address of the cell containing the first (or only) instance of the minimum of a list. However. if you're looking up a value in column B. replace "A:A" with the column containing the retrieval data.

MATCH(MAX(COUNTIF(Rng.0)) Where Rng is the range containing the data. it is useful to be able to return the N highest or lowest values from a range of data. Removing Blank Cells In A Range The procedures for creating a new list consisting of only those entries in another list. Ranking Numbers Often. the address of the first '5' in the range.Address Of First Maximum In A Range To return the address of the cell containing the first instance of the maximum of a list. Summing Every Nth Value .ROW(NumRange)*(NumRange<>""))).SMALL(RankRng.COUNTIF(Rng. Most Common String In A Range The following array formula will return the most frequently used entry in a range: =INDEX(Rng. and enter into it the number of values you want to return (e. are described in NoBlanks.ROW(NumRange))). and use Fill Down to fill out the range: =IF(ROW()-ROW(TopRng)+1>TopN. use the following array formula: =ADDRESS(MAX(IF(NumRange=MAX(NumRange). 5 for the top 5 values in RankRng). Address Of The Last Maximum In A Range To return the address of the cell containing the last instance of the maximum of a list.ROW()-ROW(TopRng)+1)) The list of numbers returned by these functions will automatically change as you change the contents of RankRng or TopN. COLUMN(NumRange).g. the address of the last '5' in the range."". Suppose we have a range of numeric data called RankRng. Also.4) This function returns B5.LARGE(RankRng. See the Ranking page for much more information about ranking numbers in Excel. with the same number of rows) called TopRng. Create a range next to RankRng (starting in the same row.ROW()-ROW(TopRng)+1)) To return the TopN smallest values of RankRng. create a named cell called TopN. use =IF(ROW()-ROW(TopRng)+1>TopN.. excluding blank cells."". Enter the following formula in the first cell in TopRng.4) This function returns B1.COLUMN(NumRange). Download a workbook illustrating these formulas. use the following array formula: =ADDRESS(MIN(IF(NumRange=MAX(NumRange). Download a workbook illustrating these formulas.Rng)).Rng).

FIND("]".$A$1:$A$20.FIND("]". This will return "C:\Files\[MyBook. etc.CELL("filename".$B$3:B$22. without the path.Xls. A9.0)) If your data ranges does not begin in row 1.A1))+1. To sum the values in rows 5.A1)."[".FIND("]".A1).FIND("]". 8. use =CELL("filename".$B$3:B$22.xls]MySheet" To return the sheet name.$D$1)=0."") .. Suppose your data is in A1:A20.CELL("filename". =SUM(IF(MOD(ROW($A$1:$A$20). use either =LEFT(CELL("filename".A1))) This will return "MySheet" File Name Suppose our active sheet is named "MySheet" in the file C:\Files\MyBook.A1))-FIND("[". etc. etc. the formulas are slightly more complicated.A1) Note that the argument to the =CELL function is the word "filename" in quotes. and N = 3 is in D1.0)) Download a workbook illustrating these formulas.xls" To return the file name with the path.CELL("filename".A1))+1.A1). etc. use =MID(CELL("filename".A1))) Or =SUBSTITUTE(SUBSTITUTE(LEFT(CELL("filename". CELL("filename". For example. use the following array formula: =SUM(IF(MOD(ROW($B$3:$B$22)-ROW($B$3). and N = 3 is in D1.$D$1)=0. 9.CELL("filename". A7. suppose you want to sum every 3rd cell."").A1))-FIND("]". LEN(CELL("filename".A1). 6. use =MID(CELL("filename". use the following array formula: =SUM(IF(MOD(ROW($B$3:$B$22)-ROW($B$3)+1. To return the full sheet name (including the file path) to a cell.CELL("filename". To return the file name without the path.$D$1)=0. 11.FIND("[". A4.0)) If you want to sum the values in A1. Miscellaneous Sheet Name Suppose our active sheet is named "MySheet" in the file C:\Files\MyBook. not your actual filename. CELL("filename".A1)))."]". A6. use the following array formula: =SUM(IF(MOD(ROW($A$1:$A$20)-1.0)) If you want to sum the values in rows 3.Xls.You can easily sum (or average) every Nth cell in a column range. Suppose our data is in B3:B22.A1))-1) This will return "MyBook. The following array formula will sum the values in A3.$A$1:$A$20.$D$1)=0.

com www.The first syntax will return "C:\Files\[MyBook. 320+ online tutorials.voxtelecom.co.xls" In all of the examples above.excel-skills. not the sheet actually containing the formula.excelintegration. the cell would contain the name of the active sheet. the A1 argument to the =CELL function forces Excel to get the sheet name from the sheet containing the formula. Excel Lookup Functions Learn how to use Excel lookup functions. and Excel calculates the =CELL function when another sheet is active. Get 2 GB Free ADSL 2GB Free ADSL Offer From Vox Click to Call Us Today www.za Alchemex Excel Reporting Automate all your Excel reports as the 1st step to Self Service BI .xls]" The second syntax will return "C:\Files\MyBook.za www. Download a workbook illustrating these formulas. Without it.co.