How-to recipes · Lookups
How to do a case-sensitive lookup in Excel
VLOOKUP, XLOOKUP and MATCH ignore upper and lower case. Combine them with EXACT to find the value whose case matches exactly.
Excel's lookup functions treat xk-20, XK-20 and Xk-20 as the same text. Most of the time that is helpful. But some systems use case-sensitive codes: product SKUs, voucher codes, short IDs generated by websites, or Base64 keys where aB3 and Ab3 are different records. If your list contains codes that differ only in case, VLOOKUP and XLOOKUP silently return the first one they find, which may be the wrong product. The fix is to let EXACT do the comparison.
The example data
Five SKUs in A2:A6 with prices in B. Three of them are variations of XK-20 in different case. We look up XK-20 (all capitals), typed in E1, and expect the price 22.
The problem in one line
=XLOOKUP(E1,A2:A6,B2:B6) returns 15, the price of xk-20 in row 2, because that is the first value that matches when case is ignored. VLOOKUP and MATCH do exactly the same.
Microsoft 365 and Excel 2021: XLOOKUP + EXACT
EXACT compares two texts and returns TRUE only when they are identical, including case. Given a range, it compares every cell and returns an array of TRUE/FALSE values. XLOOKUP then searches that array for TRUE:
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | SKU | Price | Find | XK-20 | |
| 2 | xk-20 | 15 | Price | 22 | |
| 3 | XK-20 | 22 | |||
| 4 | Xk-20 | 19 | |||
| 5 | XK-21 | 30 | |||
| 6 | xk-21 | 26 |
EXACT returns {FALSE;TRUE;FALSE;FALSE;FALSE}; the TRUE is in position 2, so XLOOKUP returns the 2nd price.
Result: 22
EXACT(A2:A6,E1)tests each SKU against XK-20 with case: only A3 passes.XLOOKUP(TRUE, ...)finds the first TRUE in that array.- The third argument, B2:B6, supplies the value in the same position: 22.
- If no SKU matches exactly, the fourth argument shows Not found instead of
#N/A.
Excel 2016 and 2019: INDEX + MATCH + EXACT
The same logic with INDEX and MATCH:
=INDEX(B2:B6,MATCH(TRUE,EXACT(A2:A6,E1),0)){=...}. With a plain Enter it may return #N/A. To avoid the special key, use MATCH(TRUE,INDEX(EXACT(A2:A6,E1),0),0) inside the INDEX.Numbers only: SUMPRODUCT
When the value you return is a number and each code appears once, SUMPRODUCT is a short alternative that needs no special keys in any version:
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | SKU | Price | Find | XK-20 | |
| 2 | xk-20 | 15 | Price | 22 | |
| 3 | XK-20 | 22 | |||
| 4 | Xk-20 | 19 | |||
| 5 | XK-21 | 30 | |||
| 6 | xk-21 | 26 |
The TRUE/FALSE array becomes 1/0 and is multiplied by the prices; only the matching price survives.
Result: 22
Be careful: if two rows match exactly, SUMPRODUCT adds their prices, and if none match it returns 0 rather than an error, which can look like a real price. Use it only when codes are guaranteed unique.
Case-sensitive counting and checking
- Count exact-case matches:
=SUMPRODUCT(--EXACT(A2:A6,E1))returns 1 here, whileCOUNTIF(A2:A6,E1)returns 3. - Check whether an exact-case code exists:
=OR(EXACT(A2:A6,E1))returns TRUE or FALSE (Ctrl+Shift+Enter in older versions). - Find case-sensitive text inside a longer text: FIND is case-sensitive, SEARCH is not. See How to check if a cell contains a word in Excel.
Pitfalls
- EXACT also distinguishes spaces and invisible characters, so
XK-20with a trailing space will not match. Clean imported codes with TRIM and CLEAN first. - EXACT compares numbers as text:
EXACT(100,"100")is TRUE. That is usually what you want for codes. - On very large lists (100,000+ rows), an EXACT array is slower than a normal lookup. A helper column with
=EXACT(A2,$E$1)and an ordinary lookup for TRUE can be faster. - Remove Duplicates and UNIQUE are not case-sensitive either, so they would merge these SKUs into one. Keep that in mind when cleaning such data.
A practical rule of thumb: whenever a list comes from a system where codes are generated automatically, check first whether case matters by counting with =SUMPRODUCT(--EXACT(A2:A6,E1)) and with COUNTIF. If the two counts differ, the list contains codes that differ only in case, and every ordinary lookup on that list is a risk.