# How to make an IF comparison case-sensitive in Excel

Use EXACT as the test: =IF(EXACT(B2,$F$1),"Valid","Invalid"). The = operator ignores case; EXACT doesn't.

**Excel:** `=IF(EXACT(B2,$F$1),"Valid","Invalid")` (Every current version)

**Google Sheets:** the same formula works.

## Example

Sample data (row 1 is the header):

| A | B | C | D | E | F |
| --- | --- | --- | --- | --- | --- |
| Order | Coupon entered | Accepted? |  | Valid code | SAVE20 |
| 1001 | SAVE20 |  |  |  |  |
| 1002 | save20 |  |  |  |  |
| 1003 | Save20 |  |  |  |  |
| 1004 | SAVE20 |  |  |  |  |
| 1005 | SAVE2O |  |  |  |  |
| 1006 | SAVE20 |  |  |  |  |

Formula in C2, filled to C7: `=IF(EXACT(B2,$F$1),"Valid","Invalid")`

Result: Valid; Invalid; Invalid; Valid; Invalid; Invalid

## How it works

EXACT compares two texts character by character, including case, and returns TRUE only for an identical match. It rejects "save20" and "Save20", the letter O typed instead of a zero in order 1005, and the trailing space in order 1006.

## Other ways

- `=IF(B2=$F$1,"Valid","Invalid")`: The plain = ignores case. Use it when case doesn't matter. ("save20" and "Save20" are accepted.)
- `=IF(EXACT(TRIM(B2),$F$1),"Valid","Invalid")`: Forgives stray spaces but still checks case. (Order 1006, with a trailing space, is accepted.)

## Common mistakes

- EXACT also checks spaces, so "SAVE20 " fails. Wrap the entry in TRIM if spaces shouldn't count.
- COUNTIF, MATCH, VLOOKUP and XLOOKUP all ignore case too. Combine them with EXACT for case-sensitive lookups.

## Questions

**How do I do a case-sensitive lookup?**

`=XLOOKUP(TRUE,EXACT(A2:A9,F1),B2:B9)` returns the row that matches exactly, including case.

**How do I check for a case-sensitive partial match?**

FIND is the case-sensitive version of SEARCH: `=ISNUMBER(FIND("SAVE",B2))`.

Every formula and result on this page was checked by running it in the Spreadsheet Practice formula engine on 2026-10-30.

Source: https://spreadsheetpractice.com/formulas/case-sensitive-if
