# If this AND that

To do something when two cells have specific values (i.e. this AND that) that you can use the IF function together with the AND function to run a test. In cell D6, the formula is:

which returns "x" when B6 is "red" AND C6 is "small", and returns an empty string ("") if not.

To do something specific when two or more conditions are TRUE, you can use the IF function in combination with the AND function to evaluate conditions with a test, then take one action if the result is TRUE, and (optionally) do take another if the result of the test is FALSE.

In the example shown, we simply want to "flag" records where the color is red AND the size is small. In other words, we want to check cells in column B for the color "red" AND check cells in column C to see if the size is "small". Then, if both conditions are TRUE, we mark the row with an "x". In D6, the formula is:

In this formula, the logical test is this bit:

AND(B6="red",C6="small")

This snippet will return TRUE only if the value in B6 is "red" AND the value in C6 is "small". If either condition isn't true, the test will return FALSE.

Next, we need to take an action when the result of the test is TRUE. In this case, we do that by adding an "x" to column D. If the test is FALSE, we simply add an empty string (""). This causes an "x" to appear in column D when both conditions are true and nothing to display if not.

*Note: if we didn't add the empty string when FALSE, the formula would actually display FALSE whenever the color is not red.*

### Testing the same cell

In the example above, we are checking two different cells, but there nothing that prevents you from running two tests on the same cell. For example, let's say you want to check values in column A and then do something when a value at least 100 but less than 200. In that case you could use this code for the logical test:

=AND(A1>=100,A1<200)

## Excel Formula Training

Formulas are the key to getting things done in Excel. In this accelerated training, you'll learn how to use formulas to manipulate text, work with dates and times, lookup values with VLOOKUP and INDEX & MATCH, count and sum with criteria, dynamically rank values, and create dynamic ranges. You'll also learn how to troubleshoot, trace errors, and fix problems. Instant access. See details here.

## Download 100+ Important Excel Functions

Get over 100 Excel Functions you should know in one handy PDF.