How to make an IF comparison case-sensitive in Excel
Formula (Excel and Google Sheets)
=IF(EXACT(B2,$F$1),"Valid","Invalid")Use EXACT as the test: =IF(EXACT(B2,$F$1),"Valid","Invalid"). The = operator ignores case; EXACT doesn't.
- Result on the example
- one result per row in
C2, filled down toC7 - Works in
- Every current version
- Google Sheets
- Same formula
See it work
The formula is already in C2, filled down to C7. Change any input and the result updates, or edit the formula to experiment.
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.
=IF(EXACT(B2,$F$1),"Valid","Invalid")Result"Valid"
B2"SAVE20"The value in B2.
$F$1"SAVE20"The value in F1.
EXACT(B2,$F$1)TRUEEXACT: TRUE if two texts match exactly, including case.- text1
B2"SAVE20" - text2
$F$1"SAVE20"
- text1
IF(EXACT(B2,$F$1),"Valid","Invalid")"Valid"IF: Returns one value if a test is true, another if false.- logical_test
EXACT(B2,$F$1)TRUE - value_if_true
"Valid" - value_if_false
"Invalid"not used
- logical_test
In Google Sheets
The same formula works in Google Sheets: =IF(EXACT(B2,$F$1),"Valid","Invalid"). We ran it in Google Sheets mode on the same data and it returns the same results.
Other ways to do it
Each one was run on the same example sheet.
| Formula | Result | When to use it |
|---|---|---|
| =IF(B2=$F$1,"Valid","Invalid") | Valid, Valid, Valid…Different result | The plain = ignores case. Use it when case doesn't matter. "save20" and "Save20" are accepted. |
| =IF(EXACT(TRIM(B2),$F$1),"Valid","Invalid") | Valid, Invalid, Invalid…Different result | 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.
Try it yourself
Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.
Make an IF comparison case-sensitive
C2, show "Valid" only when the coupon matches the code in F1 exactly, including upper and lower case, otherwise "Invalid". Fill down to C7.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)).
Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine, in both Excel and Google Sheets modes.