You are on page 1of 34

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: =SUM((A1:A10>=5)*(A1:A10<=10)*A1:A10)

Counting Characters In A String


The following formula will count the number of "B"s, both upper and lower case, in the string in B1. =LEN(B1)-LEN(SUBSTITUTE(SUBSTITUTE(B1,"B",""),"b",""))

Date And Time Formulas


A variety of formulas useful when working with dates and times are described on the DateTime page. Other Date Related Procedures are described on the following pages. 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. These procedures are described in Duplicates.

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 N non-blank cells in A2:A20. Define a name called MyRange, and set the Refers To property to: =OFFSET(Sheet1!$A$2,0,0,COUNTA($A$2:$A$20),1) Be sure to use absolute cell references in the formula. Also see then Named Ranges page for more information about dynamic ranges.

Finding The Used Part Of A Range


Suppose we've got a range of data called DataRange2, defined as H7:I25, and that cells H7:I17 actually 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: =ADDRESS(ROW(DataRange2),COLUMN(DataRange2),4)&":"& ADDRESS(MAX((DataRange2<>"")*ROW(DataRange2)),COLUMN(DataRange2)+ COLUMNS(DataRange2)-1,4) This will return the range H7:I17. If you need the worksheet name in the returned range,

use the following array formula: =ADDRESS(ROW(DataRange2),COLUMN(DataRange2),4,,"MySheet")&":"& ADDRESS(MAX((DataRange2<>"")*ROW(DataRange2)),COLUMN(DataRange2) + COLUMNS(DataRange2)-1,4) This will return MySheet!H7:I17. To find the number of rows that contain data, use the following array formula: =(MAX((DataRange2<>"")*ROW(DataRange2)))-ROW(DataRange2)+1 This will return the number 11, indicating that the first 11 rows of DataRange2 contain data. To find the last entry in the first column of DataRange2, use the following array formula: =INDIRECT(ADDRESS(MAX((DataRange2<>"")*ROW(DataRange2)), COLUMN(DataRange2),4)) To find the last entry in the second column of DataRange2, use the following array formula: =INDIRECT(ADDRESS(MAX((DataRange2<>"")*ROW(DataRange2)), COLUMN(DataRange2)+1,4))

First And Last Names


Suppose you've got a range of data consisting of people's first and last names. There are several formulas that will break the names apart into first and last names separately. Suppose cell A2 contains the name "John A Smith". To return the last name, use =RIGHT(A2,LEN(A2)-FIND("*",SUBSTITUTE(A2," ","*",LEN(A2)LEN(SUBSTITUTE(A2," ",""))))) To return the first name, including the middle name (if present), use

=LEFT(A2,FIND("*",SUBSTITUTE(A2," ","*",LEN(A2)LEN(SUBSTITUTE(A2," ",""))))-1) To return the first name, without the middle name (if present), use =LEFT(B2,FIND(" ",B2,1)) We can extend these ideas to the following. Suppose A1 contains the string "First Second Third Last".

Returning First Word In A String


=LEFT(A1,FIND(" ",A1,1)) This will return the word "First".

Returning Last Word In A String


=RIGHT(A1,LEN(A1)-MAX(ROW(INDIRECT("1:"&LEN(A1))) *(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)=" "))) This formula in as array formula. (This formula comes from Laurent Longre). This will return the word "Last"

Returning All But First Word In A String


=RIGHT(A1,LEN(A1)-FIND(" ",A1,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. To return any single word from a single-spaced string of words, use the following array formula: =MID(A10,SMALL(IF(MID(" ("1:"&LEN(A10)+1)),1)=" B10),SUM(SMALL(IF(MID(" ("1:"&LEN(A10)+2)),1)=" B10+{0,1})*{-1,1})-1) "&A10,ROW(INDIRECT ",ROW(INDIRECT("1:"&LEN(A10)+1))), "&A10&" ",ROW(INDIRECT ",ROW(INDIRECT("1:"&LEN(A10)+2))),

Where A10 is the cell containing the text, and B10 is the number of the word you want to get. This formula can be extended to get any set of words in the string. To get the words from M for N words (e.g., the 5th word for 3, or the 5th, 6th, and 7th words), use the following array formula:

=MID(A10,SMALL(IF(MID(" "&A10,ROW(INDIRECT ("1:"&LEN(A10)+1)),1)=" ",ROW(INDIRECT("1:"&LEN(A10)+1))), B10),SUM(SMALL(IF(MID(" "&A10&" ",ROW(INDIRECT ("1:"&LEN(A10)+2)),1)=" ",ROW(INDIRECT("1:"&LEN(A10)+2))), B10+C10*{0,1})*{-1,1})-1) Where A10 is the cell containg the text, B10 is the number of the word to get, and C10 is the number of words, starting at B10, to get. Note that in the above array formulas, the {0,1} and {-1,1} are enclosed in array braces (curly brackets {} ) not parentheses. Download a workbook illustrating these formulas.

Grades
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";60,"D";70,"C";80,"B";90,"A"} Then, use VLOOKUP to convert the number to the grade: =VLOOKUP(A1,Grades,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.

High And Low Values


You can use Excel's Circular Reference tool to have a cell that contains the highest ever reached value. For example, suppose you have a worksheet used to track team scores. You can set up a cell that will contain the highest score ever reached, even if that score is deleted from the list. Suppose the score are in A1:A10. First, go to the Tools>Options dialog, click on the Calculation tab, and check the Interations check box. Then, enter the following formula in cell B1: =MAX(A1:A10,B1)

Cell B1 will contian the highest value that has ever been present in A1:A10, even if that value is deleted from the range. Use the =MIN function to get the lowest ever value. Another method to do this, without using circular references, is provided by Laurent Longre, and uses the CALL function to access the Excel4 macro function library. Click here for details.

Left Lookups
The easiest way do table lookups is with the =VLOOKUP function. However, =VLOOKUP requires 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: =INDIRECT(ADDRESS(ROW(Rng)+MATCH(C1,Rng,0)-1,COLUMN(Rng)ColsToLeft)) Or =INDIRECT(ADDRESS(ROW(Rng)+MATCH(C1,Rng,0)-1,COLUMN(A:A) )) Where Rng is the range containing the lookup values, and ColsToLeft is the number of columns to the left of Rng that the retrieval values are. In the second syntax, replace "A:A" with the column containing the retrieval data. In both examples, C1 is the value you want to look up. See the Lookups page for many more examples of lookup formulas.

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. Suppose we've got a range of numeric values called NumRange. NumRange may contain duplicate values. 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, use the following array formula: =ADDRESS(MIN(IF(NumRange=MIN(NumRange),ROW(NumRange))),COLUMN(Num Range),4) This function returns B2, the address of the first '1' in the range. 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 the following array formula: =ADDRESS(MAX(IF(NumRange=MIN(NumRange),ROW(NumRange)*(NumRange<>"" ))), COLUMN(NumRange),4) This function returns B4, the address of the last '1' 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, use the following array formula: =ADDRESS(MIN(IF(NumRange=MAX(NumRange),ROW(NumRange))),COLUMN(Num Range),4) This function returns B1, the address of the first '5' in the range. 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, use the following array formula:

=ADDRESS(MAX(IF(NumRange=MAX(NumRange),ROW(NumRange)*(NumRange<>" "))), COLUMN(NumRange),4) This function returns B5, the address of the last '5' in the range. Download a workbook illustrating these formulas.

Most Common String In A Range


The following array formula will return the most frequently used entry in a range: =INDEX(Rng,MATCH(MAX(COUNTIF(Rng,Rng)),COUNTIF(Rng,Rng),0)) Where Rng is the range containing the data.

Ranking Numbers
Often, it is useful to be able to return the N highest or lowest values from a range of data. Suppose we have a range of numeric data called RankRng. Create a range next to RankRng (starting in the same row, with the same number of rows) called TopRng. Also, create a named cell called TopN, and enter into it the number of values you want to return (e.g., 5 for the top 5 values in RankRng). Enter the following formula in the first cell in TopRng, and use Fill Down to fill out the range: =IF(ROW()-ROW(TopRng)+1>TopN,"",LARGE(RankRng,ROW()ROW(TopRng)+1)) To return the TopN smallest values of RankRng, use =IF(ROW()-ROW(TopRng)+1>TopN,"",SMALL(RankRng,ROW()-ROW(TopRng)+1)) The list of numbers returned by these functions will automatically change as you change the contents of RankRng or TopN. Download a workbook illustrating these formulas.

See the Ranking page for much more information about ranking numbers in Excel.

Removing Blank Cells In A Range


The procedures for creating a new list consisting of only those entries in another list, excluding blank cells, are described in NoBlanks.

Summing Every Nth Value


You can easily sum (or average) every Nth cell in a column range. For example, suppose you want to sum every 3rd cell. Suppose your data is in A1:A20, and N = 3 is in D1. The following array formula will sum the values in A3, A6, A9, etc. =SUM(IF(MOD(ROW($A$1:$A$20),$D$1)=0,$A$1:$A$20,0)) If you want to sum the values in A1, A4, A7, etc., use the following array formula: =SUM(IF(MOD(ROW($A$1:$A$20)-1,$D$1)=0,$A$1:$A$20,0)) If your data ranges does not begin in row 1, the formulas are slightly more complicated. Suppose our data is in B3:B22, and N = 3 is in D1. To sum the values in rows 5, 8, 11, etc, use the following array formula: =SUM(IF(MOD(ROW($B$3:$B$22)-ROW($B$3)+1,$D$1)=0,$B$3:B$22,0)) If you want to sum the values in rows 3, 6, 9, etc, use the following array formula: =SUM(IF(MOD(ROW($B$3:$B$22)-ROW($B$3),$D$1)=0,$B$3:B$22,0)) Download a workbook illustrating these formulas.

Miscellaneous
Sheet Name

Suppose our active sheet is named "MySheet" in the file C:\Files\MyBook.Xls. To return the full sheet name (including the file path) to a cell, use =CELL("filename",A1) Note that the argument to the =CELL function is the word "filename" in quotes, not your actual filename. This will return "C:\Files\[MyBook.xls]MySheet" To return the sheet name, without the path, use =MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1, LEN(CELL("filename",A1))-FIND("]",CELL("filename",A1))) This will return "MySheet" 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 =MID(CELL("filename",A1),FIND("[",CELL("filename",A1))+1,FIND("]", CELL("filename",A1))-FIND("[",CELL("filename",A1))-1) This will return "MyBook.xls" To return the file name with the path, use either =LEFT(CELL("filename",A1),FIND("]",CELL("filename",A1))) Or =SUBSTITUTE(SUBSTITUTE(LEFT(CELL("filename",A1),FIND("]", CELL("filename",A1))),"[",""),"]","") The first syntax will return "C:\Files\[MyBook.xls]" The second syntax will return "C:\Files\MyBook.xls" In all of the examples above, the A1 argument to the =CELL function forces Excel to get the sheet name from the sheet containing the formula. Without it, and Excel calculates the =CELL function 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.

Formula =COUNTIF(B2:B7,">9000")

Description (Result) The COUNTIF function counts the number of cells in the range B2:B7 that contain numbers greater than 9000 (4) The COUNTIF function counts the number of cells in the range B2:B7 that contain numbers less than 9000 (4) The COUNTIFS function (available in Excel 2007 and later) counts the number of cells in the range B2:B7 greater than or equal to 9000 and are less than or equal to 22500 (4)

=COUNTIF(B2:B7,"<=9000")

=COUNTIFS(B2:B7,">=9000",B2:B7,"<=22500")

=SUMPRODUCT((B2:B7>=9000)*(B2:B7<=22500))The SUMPRODUCT function counts the number of cells in the range B2:B7 that contain numbers greater than or equal to 9000 and less than or equal to 22500 (4). You can use this function in Excel 2003 and earlier, where COUNTIFS is not available.

Cell Counting Techniques


Category: Formulas | [Item URL]

Excel provides many ways to count cells in a range that meet various criteria:

The DCOUNT function. The data must be set up in a table, and a separate criterion range is required. The COUNT function. Simply counts the number of cells in a range that contain a number. The COUNTA function. Counts the number of non-empty cells in a range. The COUNTBLANK function. Counts the number of empty cells in a range. The COUNTIF function. Very flexible, but often not quite flexible enough.

An array formula. Useful when the other techniques won't work.

Formula Examples
Listed below are some formula examples that demonstrate various counting techniques. These formula all use a range named data. To count the number of cells that contain a negative number:
=COUNTIF(data,"<0")

To count the number of cells that contain the word "yes" (not case sensitive):
=COUNTIF(data,"yes")

To count the number of cells that contain any text:


=COUNTIF(data,"*")

To count the number of cells that contain text that begins with the letter "s" (not case-sensitive):
=COUNTIF(data,"s*")

To count the number of cells that contain the letter "s" (not case-sensitive):
=COUNTIF(data,"*s*")

To count the number of cells that contain either "yes" or "no" (not casesensitive):
=COUNTIF(data,"yes")+COUNTIF(data,"no")

To count the number of three-letter words:


=COUNTIF(data,"???")

To count the number of cells that contain a value between 1 and 10:
=COUNTIF(data,">=1")-COUNTIF(data,">10")

To count the number of unique numeric values (ignores text entries):


=SUM(IF(FREQUENCY(data,data)>0,1,0))

To count the number of cells that contain an error value (this is an array formula, entered with Ctrl+Shift+Enter):
=SUM(IF(ISERR(data),1,0))

Using the formulas in VBA


You can also use these techniques in your VBA code. For example the VBA statement below calculates the number of three-letter words in a range named data, and assigns the value to the NumWords variable:
NumWords = Application.COUNTIF(Sheets("Sheet1").Range("data"), "???")

The other formula examples listed above can also be converted to VBA.

How to create a conditional format to hide errors in Excel


Article ID: 182189 - View products that this article applies to.

This article was previously published under Q182189 Expand all | Collapse all

On This Page
o o SUMMARY MORE INFORMATION Microsoft Office Excel 2003 and earlier versions of Excel Microsoft Office Excel 2007 Properties Give Feedback

<style>.tocTitle, #tocDiv{display: none;}</style>

SUMMARY
In Microsoft Excel, you can create conditional formatting on a cell or on a range of cells so that error values are not displayed in the cell(s). Back to the top | Give Feedback

MORE INFORMATION
In versions of Excel that are earlier than Microsoft Excel 97, you could not create a custom conditional format to hide error values that were returned to the cell by the cell formula. For example, #DIV/0! is returned to cell A1 if you enter the following data in the worksheet: A1: =B1/C1 B1: 5 C1: 0 To hide the error value, you can change the formula in cell A1 to the following formula:

=IF(ISERROR(B1/C1),"",B1/C1) In these examples, this formula returns the empty string (""). In Microsoft Office Excel 2007, you can use the IFERROR function to simplify this formula, as follows: =IFERROR(B1/C1,"") Note that there are other techniques for hiding error values that you can use in versions of Excel that are earlier than Excel 97. Conditional formatting allows you to use the simpler of the two formulas in cell A1 and still prevent the error value from appearing in cell A1. To use conditional formatting to hide error values that are returned by formulas in cells, use one of the following sample procedures, as appropriate for the version of Excel that you are running.

Microsoft Office Excel 2003 and earlier versions of Excel


1. Enter the following data in a worksheet: 2. A1: =B1/C1 B1: 5 C1: 0 3. A2: =nofunction()*B2 B2: 6 C2: 0 Note Cell A1 returns the #DIV/0! error value, and cell A2 returns the #NAME? error value. This occurs because the nofunction() function that is used in cell A2 is not a valid function. Select column A. On the Format menu, click Conditional Formatting. In the Conditional Formatting dialog box, click Condition 1, and then click Formula Is. In the edit box to the right of Condition 1, type the following formula: =ISERROR(A1) Click the Format button. In the Format Cells dialog box, click Color, and then click the White square. Click OK in the Format Cells dialog box, and then click OK in the Conditional Formatting dialog box. Note Because you selected column A in step 2, all the cells in column A were formatted with this conditional format. Therefore, any other cells in column A that return error values will not display the error value.

4. 5. 6. 7. 8. 9.

Microsoft Office Excel 2007


1. Enter the following data in a worksheet: 2. A1: =B1/C1 B1: 5 C1: 0 3. A2: =nofunction()*B2 B2: 6 C2: 0 Note Cell A1 returns the #DIV/0! error value, and cell A2 returns the #NAME? error value. This occurs because the nofunction() function that is used in cell A2 is not a valid function. Select column A.

4.

5.

On the Home tab, click the arrow next to Conditional Formatting in the Styles group, and then click New Rule. 6. In the New Formatting Rule dialog box, click Use a formula to determine which cells to format. 7. In the Edit the Rule Description box, type the following formula in the Format values where this formula is true field: =ISERROR(A1) 8. Click the Format button. 9. In the Format Cells dialog box, click the Font tab, and then click the White square in the Color list. 10. Click OK, and then click OK in the New Formatting Rule dialog box. Note Because you selected column A in step 2, all the cells in column A were formatted with this conditional format. Therefore, any other cells in column A that return error values will not display the error value.

HOW TO LIMIT THE USABLE AREA IN AN EXCEL WORKSHEET

To control or limit the scroll area of an Excel worksheet be used to either guide or restrict the user to only use areas they are required to, or you want to allow access to or allow for ease of navigation on a worksheet. There are two ways to achieve this restriction. The difference between the two methods is dependent on whether you need a temporary or more permanent solution. Let's take the temporary solution first. This way is to Set The Scroll Area Property. 1. First of all you need to make sure the Developer Tab is visible in Excel. If it is not you need to enable it. You can easily do this by selecting:

Excel Options Popular Show Developer Tab

2. Select Developer 3. Controls 4. Properties

5. In the properties window enter the scroll area you want to. This has to be entered manually (typed) in. For Example a cell range of A2:D10 you need to type in A2:D10. After you have typed in your range of cells, you can then only scroll those few cells and cannot activate anything outside that set area. This is great method if you need to limit access to a table in that range of cells. As already stated this unfortunately this is not a persistent or permanent feature. The scroll area property is reset when you save your file, close it then reopen it. If this does not provide the solution you need there is an alternative way to set the scroll area in an Excel worksheet. This involves a small piece of Visual Basic (VB) knowledge which I will share with you. 1. Hit ALT + F11 keys on your keyboard to open the visual basic editor in Excel 2. Click on 'ThisWorkBook 'in the Project VBA Window 3. You will now see the 'ThisWorkbook 'code module- double on it click to open it 4. Enter or copy the following code into 'ThisWorkbook' code module Private Sub Workbook_Open() Worksheets("Sheet1"). ScrollArea = "A2:D10" End Sub 5. Press ALT+F11 to exit out of the VB editor to return to Excel normal view 6. Save the workbook as normal and then re open it. If your workbook has an .xlsm extension it will need to be saved as as macro enabled workbook (.xlsm) extension to allow this feature to work. This will be a permanent way to set the scroll area in your workbook until you decide to change it.

Article Source: http://EzineArticles.com/6739488 By Mr.Byte October 16, 2008

If you are new here, Subscribe to Full Feeds or by Email or follow us in Twitter and receive free daily updates on Office and Windows Tips, Tricks and Tweaks.. Sometimes it may be needed to calculate the average of a column of cells excluding all the zeros in any of the cells. It may be little tricky for novice Excel users if they dont know how to use multiple formulas in conjunction. Though we can use same method in both Excel 2003 and Excel 2007, the later gives much easier new features that we can use. So, lets see how to Average Non-zero values in Excel 2003 and Excel 2007? First lets see how to calculate non-zero average in Excel 2003. Assume we have to take non-zero average of cells from A1 to A9. We normally use =AVERAGE(A1:A9) to calculate regular average. This will take zeros for calculation and will return wrong result. You can use two formulas (SUM and COUNTIF) together to get the desired result. =SUM(A1:A9)/COUNTIF(A1:A9,"<>0") takes the sum of all cells from A1 to A9 but counts only cells if they are not equal to zero. You can also change the formula to use SUMIF and COUNTIF with >0 etc. Another method is by using the Array Formula or CSE formula. This helps to implement AVERAGEIF feature which is not available in Excel 2003. {=AVERAGE(IF(A1:A9>0,A1:A9))} Note: All the array formula must be started and ended with curly braces {}, you can get the braces by pressing CTRL + SHIFT + ENTER, rather than pressing just Enter alone after entering the formula. Well learn more about Array Formulas in another post soon.

In Excel from Office 2007, you can also use all the same formula as in Excel 2003. But you can also take advantage of new formulas available like built-in AVERAGEIF. To achieve non-zero average, we can use the formula, =AVERAGEIF(A1:A9,"<>0",A1:A9)

Note: In the images above, the condition is written as >0 which will remove any negative numbers as well. In that case you may be required to use the condition <>0.

Access Query and Filter Criteria


When constructing a query or a filter, you need to tell Access what to look for in each field. You do this by defining criteria - typing something (an "expression") into the Criteria cell of the query or filter grid. If you do not define any criteria for a particular field, Access assumes that you are applying no constraints and will display everything it has. This means that you only have to define criteria for those fields you are interested in. Here are some examples of the more common types of criteria. Often Access will complete the expression so that you need only type the text you want to match. However, sometimes Access has a choice so you should always check that what Access has written is the same as you intended. If what you type doesn't make sense to Access, you will see an error message. The list of examples below is not exhaustive. Try using combinations of different expressions and see what you get. Also, don't immediately assume that you have made a mistake if you get no records when you run the query or

filter. It means that Access can't find anything to match your criteria. That may be because you've asked for something impossible, but it could equally mean that your criteria were perfectly OK but there simply aren't any matching records. This tutorial is arranged in the following sections: Matching Text Using Wildcards Working with Numbers Working with Dates Excluding Things Finding Empty Fields

Matching Text When you enter text into the criteria cell your text should be enclosed in quotes ("") to distinguish it from other expressions and operators that you may need to add. "Text" To match a word or phrase simply type the text you want to match. The query will find all the records that match the text exactly. Access will add the quote marks at each end. It is only necessary to enter the quotes yourself if you type text that might confuse the query. For example you may want to type a phrase that contains the words "and" or "or". Access would normally interpret these words as instructions. You can manually insert the quote marks at each end of the phrase to make sure the criterion means what you intend it to. This example will display all the records that contain the entry London in the Town field. "Text" Or "Text" To match one of two or more words or phrases, type the text you want to match separated by the word "or". The query will find all the records that match any of the words or phrases. Enter quote marks yourself if you think the text might confuse the query. This example will display all the records that contain either London or Paris in the Town field. "Text" To match one of several words or phrases, you in a new row moving down the column. This "or" but has the advantage that your criteria example will display all the records that contain Amsterdam in the Town field. Note: If this criteria for other fields those criteria must be

"Text" can type each word or phrase gives the same result as using might be easier to read. This the entry London, Paris or method is combined with repeated for each row.

In ("Text", "Text", "Text") To match a word or phrase from a list, type the list items separated by commas, and enclose the list in round brackets (parentheses). Access will add the expression "In" and place quote marks where needed - you can do this manually if you wish. This example will display all the records that contain UK or USA or France in the Country field. Not "Text" To exclude a word or phrase, use the expression "Not" followed by the word of phrase you want to exclude (enclosed in quotes). This example will display records that contain anything other than London in the Town field. Not In ("Text", "Text", "Text") phrases from the search use the same list but add the expression "Not" at the display all records that contain anything in the Country field.

To exclude a list of words or method as for matching from a beginning. This example will other than UK or USA or France ^ top

Using Wildcards A wildcard is a special character that can stand for either a single character or a string of text. Wildcards are useful when you want the query to look for a range of different possible values, and also when you are not certain exactly what you are looking for but can give the query some clues to work with. The two wildcards we commonly use are the asterisk or star (*) and the question mark (?).The asterisk (*) represents any string of text from nothing up to an entire paragraph or more. The question mark (?) represents a single character only (although you could use, for example, two question marks to represent two unknown characters). For example: Yor* would find York, Yorkshire and Yorktown but not New York. Mar? would find Mark but not Mario, Martin or Omar. F*d would find Fred and Ferdinand but not Frederick.

Like "Text*" To match text starting with a particular letter or string type the letter or string of text followed by an asterisk. Access will add the expression "Like" and place quotes around your typing. This example will display all records that have an entry starting with S in the Company field. Like "*Text" To match text ending with a particular letter or string type an asterisk followed by

a letter or string of text. This example will display all records that have an entry ending with Plc in the Company field. Like "[Letter-Letter]*" To match text starting with letters within a certain range you must type the entire expression as shown (this one is too complicated for Access to work out what you want. This example will display all the records with entries starting with the letters A - D in the Company field. You can often get the same results by using mathematical operators such as greater than (>) and less than (<). These are normally used for specifying numbers and dates but can also be used for text. For example: <"N" would find all entries beginning with a letter lower than the letter N in the alphabet. In other words, all entries starting with the letters A - M. ^ top >"F" And <"H" would find all entries beginning with the letters F and G.

Working with Numbers When working with numbers we normally use the mathematical operators to define the range of numbers from which we want to select. For example, where X represents a number: <X finds values less than X. >X finds vales greater than X >=X finds values greater than or equal to X <>X finds vales not equal to X

It is important that your field type is correctly defined as a Number field for numerical queries to work properly. Here are some examples X To match a number simply type the number that you want the query to find. This example will display the record(s) with the entry 385 in the CustomerNumber field.

<X To find values less than a certain number type a less than sign (<) followed by the number. This example will display all records with an entry less than 1000 in the CustomerNumber field. Between X And Y To find values in a range of numbers type the Y represent the numbers at opposite ends of the all records with entries falling within the range CustomerNumber field.

expression shown where X and range. This example will display 500-700 in the ^ top

Working with Dates Dates behave the same way as numbers, so you can use some of the same techniques when constructing your date query or filter. Remember, for dates to be treated properly by Access it is important that your field type has been correctly defined as a Date/Time field. It doesn't matter how you enter the date, as long as you use a recognised format. The date will be displayed in the resulting dynaset in whatever format you chose when you created the table. When you enter a date in the criteria cell you can use any standard date format, but each date must be enclosed by hash marks (#). For example: <#1/1/98# finds dates earlier than 1 January 1998 =#27-Sep-50# finds dates equal to 27 September 1950 Between #5/7/98# And #10/7/98# finds dates no earlier than 5 July 1998 and no later than 10 July 1998 Here are some more examples =#Date# To match a particular date type the date enclosed by hash marks (#). This example will display all the records with entries for 27 September 1998 in the Invoice Date field.

=Date() To match today's date type the expression shown. Date() means "today". This

example will display all the records with entries for the current date in the Invoice Date field.

Year([Fieldname])=Year(Now()) To match the current year type the expression shown, entering the name of the current field in square brackets where indicated. This example will display all the records with entries for the current year in the Invoice Date field. Year([Fieldname])=Year expression shown, entering the brackets where indicated and the example will display all the records field.

To match a particular year type the name of the current field in square required year in place of Year. This with a date in 1998 in the Invoice Date

<Date()-30 To match a particular calculated date range you will need to use a combination of expressions. This expression employs a calculation that subtracts 30 from the current date and also includes the less than operator. This example will display all the records with a date more than 30 days old in the Invoice Date field. ^ top

Excluding Things Sometimes you want to specifically exclude criteria from your search. This is done with the expression Not. This expression can be used on its own or in combination with other expressions. For example: Not "text" finds all records except those matching the specified text. Not Like "X*" finds all records except those starting with the specified letter (or string of text). Here are some more examples: Not "Text" To exclude specific records from the search use the expression Not followed by the text which matches those records you want left out. The text needs to be between quotes as shown here - Access will normally do that for you. This example will find all records for contacts in towns other than London. Not Like "Text*" Not expression, which then becomes Not Like criteria. Here is just one example. This example

You can use wildcards with the followed by your wildcard

will find all records for contacts in towns starting will letters other than L. And Not "Text" The Not expression can be used in combination with other expressions, when it becomes And Not followed by the text you want to exclude from your search. This example will find all records for contacts in towns starting with the letter L but will exclude those in London. ^ top

Finding Empty Fields A query can be used to find records where specific fields are empty. To do this you use the expression Is Null. Conversely, to find records for which specific fields are not empty you use the expression Is Not Null. The expression Null simply means "nothing". If you have made use of the "allow zero length" field property you can search for zero length entries. Sometimes you want to distinguish between, for example, records for which you don't happen to have the particular piece of information for a certain field and those for which you know there definitely isn't any information available. Is the Fax Number field empty because you don't know the person's fax number or is it because they don't have a fax? Either way you can't type a fax number into the field. It has to be left empty. Well, not exactly You can make a "zero length entry" (providing this feature has been enabled in the properties of the field - in the table's design view). To do this when entering data type two double-quote marks together without a space between, like this "". When you leave the field the quote marks disappear and the field looks just like any other empty field - except Access knows it contains a zero length entry. You can search for zero length entries with a query. It is important to remember that if you make use of zero length entries, Is Null will not find them. It regards them as a piece of text and therefore a field containing a zero length entry is not empty, it just doesn't contain any data. Confused? Read it again then try it out - it does make sense eventually! Here are some examples: Is Null To find empty fields use the Is Null expression. This looks for fields that contain no data. This example will find all records for contacts whose fax number has not been recorded.

Is Not Null To find fields that are not empty use the Is Not Null expression. This looks for fields that contain data. If there is something in the field the record will be shown. Note that Is Not Null will find fields containing zero length entries. (If you want to leave them out try excluding them with the And Not expression.) This example finds all records for contacts whose fax number has been recorded. "" To find zero length entries use "" expression. This looks for zero length entries in

the specified field. This example would find, depending on why you had made use of the zero length entry feature, all records for contacts who did not have a fax. ^ top

As I said at the beginning, this is not an exhaustive list of query criteria. Many of these expressions can be combined to create more complex criteria. You can use calculations to construct criteria. The scope is almost limitless. Use your imagination and see what you get! Above all, remember that Access is logical. If you don't get the result you were expecting, read the grid a line at a time (which is what Access does) and see if it makes sense. Sometimes it helps to go and check out the SQL (the language Access uses to write the query - SQL stands for Structured Query Language). You can view the SQL by clicking the SQL View button on the toolbar.

MS Excel: IF Function (WS)


In Microsoft Excel, the IF function returns one value if a specified condition evaluates to TRUE, or another value if it evaluates to FALSE.

Syntax
The syntax for the IF function is: IF( condition, [value_if_true], [value_if_false] ) condition is the value that you want to test. value_if_true is optional. It is the value that is returned if condition evaluates to TRUE. value_if_false is optional. It is the value that is return if condition evaluates to FALSE.

Applies To
Excel 2011 for Mac, Excel 2010, Excel 2007, Excel 2003, Excel XP, Excel 2000

Type of Function
Worksheet function (WS)

Worksheet Function Example


Let's take a look at an example to see how you would use the IF function in a worksheet:

Based on the Excel spreadsheet above, the IF function would return the following: =IF(A1>10, "Larger", "Smaller") =IF(A1=20, "Equal", "Not Equal") =IF(A2="Tech on the Net", 12, 0) would return "Larger" would return "Not Equal" would return 12

Learn how to nest multiple IF Functions. (up to 7) Learn how to nest multiple IF Functions. (more than 7)

Frequently Asked Questions Question: In Microsoft Excel, I'd like to use the IF function to create the following logic:
if C11>=620, and C10="F"or"S", and C4<=$1,000,000, and C4<=$500,000, and C7<=85%, and C8<=90%, and C12<=50, and C14<=2, and C15="OO", and C16="N", and C19<=48, and C21="Y", then reference cell A148 on Sheet2. Otherwise, return an empty string.

Answer: The following formula would accomplish what you are trying to do:

=IF(AND(C11>=620, OR(C10="F",C10="S"), C4<=1000000, C4<=500000, C7<=0.85, C8<=0.9, C12<=50, C14<=2, C15="OO", C16="N", C19<=48, C21="Y"), Sheet2!A148, "")

Question: In Microsoft Excel, I'm trying to use the IF function to return 0 if cell A1 is either < 150,000 or
> 250,000. Otherwise, it should return A1.

Answer: You can use the OR function to perform an OR condition in the IF function as follows:
=IF(OR(A1<150000,A1>250000),0,A1) In this example, the formula will return 0 if cell A1 was either less than 150,000 or greater than 250,000. Otherwise, it will return the value in cell A1.

Question: In Microsoft Excel, I'm trying to use the IF function to return 25 if cell A1 > 100 and cell B1 <
200. Otherwise, it should return 0.

Answer: You can use the AND function to perform an AND condition in the IF function as follows:
=IF(AND(A1>100,B1<200),25,0) In this example, the formula will return 25 if cell A1 is greater than 100 and cell B1 is less than 200. Otherwise, it will return 0.

Question: In Microsoft Excel, I need to write a formula that works this way:
IF (cell A1) is less than 20, then times it by 1, IF it is greater than or equal to 20 but less than 50, then times it by 2 IF its is greater than or equal to 50 and less than 100, then times it by 3/ And if it is great or equal to than 100, then times it by 4

Answer: You can write a nested IF statement to handle this. For example:
=IF(A1<20, A1*1, IF(A1<50, A1*2, IF(A1<100, A1*3, A1*4)))

Question: In Microsoft Excel, I need a formula in cell C5 that does the following:
IF A1+B1 <= 4, return $20 IF A1+B1 > 4 but <= 9, return $35 IF A1+B1 > 9 but <= 14, return $50

IF A1+B1 > 15, return $75

Answer: In cell C5, you can write a nested IF statement that uses the AND function as follows:
=IF((A1+B1)<=4,20,IF(AND((A1+B1)>4,(A1+B1)<=9),35,IF(AND((A1+B1)>9,(A1+B1)<= 14),50,75)))

Question: In Microsoft Excel, I need a formula that does the following:


IF the value in cell A1 is BLANK, then return "BLANK" IF the value in cell A1 is TEXT, then return "TEXT" IF the value in cell A1 is NUMERIC, then return "NUM"

Answer: You can write a nested IF statement that uses the ISBLANK function, the ISTEXT function, and
the ISNUMBER function as follows: =IF(ISBLANK(A1)=TRUE,"BLANK",IF(ISTEXT(A1)=TRUE,"TEXT",IF(ISNUMBER(A1)=TRUE, "NUM","")))

Question: In Microsoft Excel, I want to write a formula for the following logic:
IF R1<0.3 AND R2<0.3 AND R3<0.42 THEN "OK" OTHERWISE "NOT OK"

Answer: You can write an IF statement that uses the AND function as follows:
=IF(AND(R1<0.3,R2<0.3,R3<0.42),"OK","NOT OK")

Question: In Microsoft Excel, I need a formula for the following:


IF cell A1= PRADIP then value will be 100 IF cell A1= PRAVIN then value will be 200 IF cell A1= PARTHA then value will be 300 IF cell A1= PAVAN then value will be 400

Answer: You can write an IF statement as follows:


=IF(A1="PRADIP",100,IF(A1="PRAVIN",200,IF(A1="PARTHA",300,IF(A1="PAVAN",400, ""))))

Question: In Microsoft Excel, I want to calculate following using an "if" formula:


if A1<100,000 then A1*.1% but minimum 25 and if A1>1,000,000 then A1*.01% but maximum 5000

Answer: You can write a nested IF statement that uses the MAX function and the MIN function as
follows: =IF(A1<100000,MAX(25,A1*0.1%),IF(A1>1000000,MIN(5000,A1*0.01%),""))

Question: In Microsoft Excel, I am trying to create an IF statement that will repopulate the data from a
particular cell if the data from the formula in the current cell equals 0. Below is my attempt at creating an IF statement that would populate the data; however, I was unsuccessful. =IF(IF(ISERROR(M24+((L24-S24)/AA24)),"0",M24+((L24-S24)/AA24)))=0,L24) The initial part of the formula calculates the EAC (Estimate At completion = AC+(BAC-EV)/CPI); however if the current EV (Earned Value) is zero, the EAC will equal zero. IF the outcome is zero, I would like the BAC (Budget At Completion), currently recorded in another cell (L24), to be repopulated in the current cell as the EAC.

Answer: You can write an IF statement that uses the OR function and the ISERROR function as follows:
=IF(OR(S24=0,ISERROR(M24+((L24-S24)/AA24))),L24,M24+((L24-S24)/AA24))

Question: I have been looking at your Excel IF, AND and OR sections and found this very helpful,
however I cannot find the right way to write a formula to express if C2 is either 1,2,3,4,5,6,7,8,9 and F2 is F and F3 is either D,F,B,L,R,C then give a value of 1 if not then 0. I have tried many formulas but just can't get it right, can you help please?

Answer: You can write an IF statement that uses the AND function and the OR function as follows:
=IF(AND(C2>=1,C2<=9, F2="F",OR(F3="D",F3="F",F3="B",F3="L",F3="R",F3="C")),1,0)

Question:In Excel, I have a roadspeed of a car in m/s in cell A1 and a drop down menu of different units
in C1 (which unclude mph and kmh). I have used the following IF function in B1 to convert the number to the unit selected from the dropdown box: =IF(C1="mph","=A1*2.23693629",IF(C1="kmh","A1*3.6")) However say if kmh was selected B1 literally just shows A1*3.6 and does not actually calculate it. Is there away to get it to calculate it instead of just showing the text message?

Answer: You are very close with your formula. Because you are performing mathematical operations
(such as A1*2.23693629 and A1*3.6), you do not need to surround the mathematical formulas in quotes. Quotes are necessary when you are evaluating strings, not performing math. Try the following: =IF(C1="mph",A1*2.23693629,IF(C1="kmh",A1*3.6))

Question:For an IF statement in Excel, I want to combine text and a value.


For example, I want to put an equation for work hours and pay. IF I am paid more than I should be, I want it to read how many hours I owe my boss. But if I work more than I am paid for, I want it to read what my boss owes me (hours*Pay per Hour). I tried the following: =IF(A2<0,"I owe boss" abs(A2) "Hours","Boss owes me" abs(A2)*15 "dollars") Is it possible or do I have to do it in 2 separate cells? (one for text and one for the value)

Answer: There are two ways that you can concatenate text and values. The first is by using the &
character to concatenate: =IF(A2<0,"I owe boss " & ABS(A2) & " Hours","Boss owes me " & ABS(A2)*15 & " dollars") Or the second method is to use the CONCATENATE function: =IF(A2<0,CONCATENATE("I owe boss ", ABS(A2)," Hours"), CONCATENATE("Boss owes me ", ABS(A2)*15, " dollars"))

Question:I have Excel 2000. IF cell A2 is greater than or equal to 0 then add to C1. IF cell B2 is greater
than or equal to 0 then subtract from C1. IF both A2 and B2 are blank then equals C1. Can you help me with the IF function on this one?

Answer: You can write a nested IF statement that uses the AND function and the ISBLANK function as
follows: =IF(AND(ISBLANK(A2)=FALSE,A2>=0),C1+A2, IF(AND(ISBLANK(B2)=FALSE,B2>=0),C1B2, IF(AND(ISBLANK(A2)=TRUE, ISBLANK(B2)=TRUE),C1,"")))

Question:How would I write this equation in Excel? IF D12<=0 then D12*L12, IF D12 is > 0 but <=600
then D12*F12, IF D12 is >600 then ((600*F12)+((D12-600)*E12))

Answer: You can write a nested IF statement as follows:

=IF(D12<=0,D12*L12,IF(D12>600,((600*F12)+((D12-600)*E12)),D12*F12))

Question:In Excel, I have this formula currently:


=IF(OR(A1>=40, B1>=40, C1>=40), "20", (A1+B1+C1)-20) If one of my salesman does sale for $40-$49, then his commission is $20; however if his/her sale is less (for example $35) then the commission is that amount minus $20 ($35-$20=$15). I have 3 columns that are needed based on the type of sale. Only one column per row will be needed. The problem is that, when left blank, the total in the formula cell is -20. I need help setting up this formula so that when the 3 columns are left blank, the cell with the formula is left blank as well.

Answer: Using the AND function and the ISBLANK function, you can write your IF statement as follows:
=IF(AND(ISBLANK(A1),ISBLANK(B1),ISBLANK(C1)),"",IF(OR(A1>40, B1>40, C1>40), "20", (A1+B1+C1)-20)) In this formula, we are using the ISBLANK function to check if all 3 cells A1, B1, and C1 are blank, and if they are return a blank value (""). Then the rest is the formula that you originally wrote.

Question:In Excel, I need to create a simple booking and and out system, that shows a date out and a
date back "A1" = allows person to input date booked out "A2" =allows person to input date booked back in "A3"= shows status of product, eg, booked out, overdue return etc. I can automate A3 with the following IF function: =IF(ISBLANK(A2),"booked out","returned") But what I cant get to work is if the product is out for 10 days or more, I would like the cell to say "send email" Can you assist?

Answer: Using the TODAY function and adding an additional IF function, you can write your formula as
follows: =IF(ISBLANK(A2),IF(TODAY()-A1>10,"send email","booked out"),"returned")

Question:Using Microsoft Excel, I need a formula in cell U2 that does the following:
IF the date in E2<=12/31/2010, return T2*0.75

IF the date in E2>12/31/2010 but <=12/31/2011, return T2*0.5 IF the date in E2>12/31/2011, return T2*0 I tried using the following formula, but it gives me #VALUE! =IF(E2<=DATE(2010,12,31),T2*0.75), IF(AND(E2>DATE(2010,12,31),E2<=DATE(2011,12,31)),T2*0.5,T2*0) Can someone please help? Thanks.

Answer: You were very close...you just need to adjust your brackets as follows:
=IF(E2<=DATE(2010,12,31),T2*0.75, IF(AND(E2>DATE(2010,12,31),E2<=DATE(2011,12,31)),T2*0.5,T2*0))

Question:In Excel, I would like to add 60 days if grade is 'A', 45 days if grade is 'B' and 30 days if grade
is 'C'. It would roughly look something like this, but I'm struggling with commas, brackets, etc. (IF C5=A)=DATE(YEAR(B5)+0,MONTH(B5)+0,DAY(B5)+60), (IF C5=B)=DATE(YEAR(B5)+0,MONTH(B5)+0,DAY(B5)+45), (IF C5=C)=DATE(YEAR(B5)+0,MONTH(B5)+0,DAY(B5)+30)

Answer:You should be able to achieve your date calculations with the following formula:
=IF(C5="A",B5+60,IF(C5="B",B5+45,IF(C5="C",B5+30)))

Question:In Excel, I am trying to write a function and can't seem to figure it out. Could you help?
IF D3 is < 31, then 1.51 IF D3 is between 31-90, then 3.40 IF D3 is between 91-120, then 4.60 IF D3 is > 121, then 5.44

Answer:You can write your formula as follows:


=IF(D3>121,5.44,IF(D3>=91,4.6,IF(D3>=31,3.4,1.51)))

You might also like