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.

Intermediate EXACT XLOOKUP INDEX MATCH SUMPRODUCT VLOOKUP

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:

E2fx=XLOOKUP(TRUE,EXACT(A2:A6,E1),B2:B6,"Not found")
ABCDE
1SKUPriceFindXK-20
2xk-2015Price22
3XK-2022
4Xk-2019
5XK-2130
6xk-2126

EXACT returns {FALSE;TRUE;FALSE;FALSE;FALSE}; the TRUE is in position 2, so XLOOKUP returns the 2nd price.

Result: 22

  1. EXACT(A2:A6,E1) tests each SKU against XK-20 with case: only A3 passes.
  2. XLOOKUP(TRUE, ...) finds the first TRUE in that array.
  3. The third argument, B2:B6, supplies the value in the same position: 22.
  4. 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:

Formula
=INDEX(B2:B6,MATCH(TRUE,EXACT(A2:A6,E1),0))
Watch out. In Excel 2016 and 2019 confirm this formula with Ctrl+Shift+Enter, because EXACT has to work on a whole range. Excel then shows it in braces {=...}. 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:

E2fx=SUMPRODUCT(--EXACT(A2:A6,E1),B2:B6)
ABCDE
1SKUPriceFindXK-20
2xk-2015Price22
3XK-2022
4Xk-2019
5XK-2130
6xk-2126

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, while COUNTIF(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-20 with 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.

Tip. Other lookup variations, such as looking to the left or matching two conditions, are in How to look up a value to the left in Excel and How to look up a value with two criteria in Excel. The basics of every lookup function are compared in Lookup guide: VLOOKUP vs INDEX/MATCH vs XLOOKUP.
⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 14 KB

More how-to recipes