Anda di halaman 1dari 3

Nesting Statement with AND

1. Open a blank workbook in Excel and enter this data: A B C D E 1 Name District Sales Emp. Yrs Job Level 2 Linda East $20,000.00 2 3 Joe West $42,302.00 9 4 Bill East $53,001.00 3 5 Mary South $12,000.00 12 6 Mark South $ 2,050.00 6 7 John North $9,000.00 0 8 Ted East $40,000.00 4 2. This data which shows your salespeoples district, annual sales, and number of years employed by your company.
3.

Now, lets suppose you want a formula in column E that will assign a job level based on two different criteria:

Salespeople who have been employed for more than 5 years AND have annual sales of more than $10,000 should be assigned a job level code of 2, and all others should have a job level code of 1.

4. To include two criteria, when both criteria must be met, you must nest an

AND function within your IF statement. Put this formula in cell E2: =IF((AND(D2>5,C2>10000)),2,1) 5. Grab cell E2 by its fill handle and drag it down to cell E8 to relatively copy it to the rest of the cells in column E.

WRITE THE ANSWER

Nesting Statement with OR


Using the same data,you can use a nested OR function if you want a job level code of 2 to be applied if an employee meets EITHER criterion, instead of both criteria. A nested OR function works the same way as an AND function, except it will return the 2, if ANY of the criteria are met, instead of requiring that ALL criteria are met. 2. Put this one in E2 now and copy it down to E8:

=IF((OR(D2>5,C2>10000)),2,1)
3. You can use more than two criteria in nested ANDs and ORs. Simply separate them by commas. 4. These examples work great when there are only two job levels, but what if there are more than two? In this case, you will have more than two criteria and more than one value if true and value if false. 5. Lets say we want to assign a job level 3 if the employee meets BOTH criteria above, a job level 2 if the employee meets EITHER criteria above, and a job level 1 if the employee doesnt meet any of the criteria above. Put this formula in E2 and copy it down to E8 =IF((AND(D2>5,C2>10000)),3,(IF((OR(D2>5,C2>10000)),2,1))) 6. Notice what we are doing here is basically nesting one IF statement within another. However, though we have two different logical tests and two different values if true, we only have one value if false. You can nest up to 7 IFs in one formula, so that means you can return up to 8 different results (7 different values if true and one value if false).

7. You can also nest multiple IFs if you want different results based on different values in the same cell. For this example, lets say all of the employees in the East district will be assigned a job level 4, the West ones will be job level 3, the North ones will be job level 2, and the ones in the South will be job level 1. Our formula would look like this: =IF((B2="East"),4,IF((B2="West"),3,IF((B2="North"),2,IF((B2="South"),1,"")))) 8.Note that the value if false is , which tells Excel to leave the cell empty if no match is found in column B for that row. If you delete the contents of any cell in column B or change it to anything other than East, West, North, or South, you will see the corresponding cell in column E would now be empty. Remember, you must have something in your third argument (value if false) or Excel will simply enter the text FALSE into that cell if it does not find a match.

Anda mungkin juga menyukai