Cellwise Try it free

Excel guide · 3 min read

Case-sensitive lookup in Excel

Quick answerVLOOKUP, XLOOKUP, MATCH and COUNTIF all ignore case, so "xk7p" and "XK7P" look identical to them. For a case-sensitive lookup in Excel 365, use =XLOOKUP(TRUE,EXACT(A2:A8,E2),B2:B8): EXACT compares with case, and XLOOKUP returns the row where it says TRUE.

Sample data

Every result on this page was calculated from this sheet by the same spreadsheet engine the Cellwise app uses.

ABCDE
1Short codeDestinationClicksLook up
2xK7p/spring-sale412Xk7P
3Xk7P/careers58
4XK7P/pricing1290
5m3Qa/blog/excel-tips237
6M3qA/webinar96
7xk7p/support145
8bT9z/newsletter503

Download this sheet as an Excel practice file (.xlsx)

Why a normal lookup returns the wrong row

Short links, Base64 IDs, some product codes and some part numbers treat xK7p and Xk7P as different values. Excel's lookup functions do not: they compare text without regard to case and return the first match they find.

You want the destination for Xk7P (row 3). VLOOKUP stops at row 2, xK7p, because to VLOOKUP it is the same code. No error appears, so the wrong answer goes unnoticed.

=VLOOKUP(E2,A2:C8,2,FALSE)

Result: /spring-sale

/spring-sale: the destination of xK7p, the first code that matches when case is ignored. The right answer is /careers.

Method 1: XLOOKUP with EXACT (Excel 365 / 2021)

EXACT(text1, text2) returns TRUE only when both texts match character for character, including case. Given a whole range, EXACT(A2:A8,E2) returns a list of TRUE and FALSE values, one per row. XLOOKUP then looks for TRUE in that list and returns the matching destination.

The full formula is =XLOOKUP(TRUE,EXACT(A2:A8,E2),B2:B8,"No exact match"). The fourth argument is the text to show when no code matches exactly. This is the clearest version to read later, so pick it if everyone who opens the file has Excel 365 or 2021.

In Excel 2019 and earlier, use =INDEX(B2:B8,MATCH(TRUE,EXACT(A2:A8,E2),0)) and confirm it with Ctrl+Shift+Enter, because older versions need that to treat it as an array formula.

Method 2: FIND with a length check

FIND is case-sensitive (SEARCH is not). FIND(E2,A2:A8) gives a position number where the code appears with the same case, and an error where it does not. ISNUMBER turns that into TRUE or FALSE. Adding LEN(A2:A8)=LEN(E2) rules out longer codes that merely contain E2, so only whole, exact matches remain.

Multiplying the two tests gives 1 for an exact match and 0 otherwise, and XLOOKUP looks for the 1. It returns the same result as the EXACT version and is handy if you already use FIND elsewhere.

=XLOOKUP(1,ISNUMBER(FIND(E2,A2:A8))*(LEN(A2:A8)=LEN(E2)),B2:B8,"No exact match")

Result: /careers

/careers: only row 3 holds Xk7P with exactly that mix of upper and lower case.

Count or sum with exact case

COUNTIF and SUMIF ignore case too. Total clicks for "xk7p" with SUMIF and you get four different links added together. Move the same exact-case test into SUMPRODUCT and multiply it by the clicks.

With EXACT the version is =SUMPRODUCT(--EXACT(A2:A8,"xK7p"),C2:C8). The FIND version below gives the same total.

=SUMPRODUCT(ISNUMBER(FIND("xK7p",A2:A8))*(LEN(A2:A8)=LEN("xK7p"))*C2:C8)

Result: 412

412 clicks for xK7p only. =SUMIF(A2:A8,"xk7p",C2:C8) returns 1,905, because it also adds Xk7P, XK7P and xk7p.

Check that two cells match exactly

The = operator is not case-sensitive either: =A2=E2 returns TRUE for xK7p and Xk7P. To compare two cells with case, use =EXACT(A2,E2), or the FIND and LEN pair in an IF when you want a label.

This is useful for spotting codes that were retyped with the wrong case, a common cause of broken short links after someone "tidies up" a list.

=IF(AND(LEN(A4)=LEN(E2),ISNUMBER(FIND(E2,A4))),"Exact match","Different")

Result: Different

Different: XK7P has the same letters as Xk7P but not the same case.

Which method to pick

Use XLOOKUP with EXACT in Excel 365 or 2021: it reads like the problem. Use INDEX/MATCH with EXACT for older versions. The FIND and LEN test does the same job; drop the LEN part when you want a case-sensitive "contains" test instead of a whole-cell match.

Other tools to know: Ctrl+F has a Match case box under Options. Data > Remove Duplicates and UNIQUE are not case-sensitive, so they treat xK7p and XK7P as duplicates. Power Query merges are case-sensitive by default, which can be what you want for large lists.

Common mistakes

Trusting VLOOKUP or XLOOKUP with mixed-case codes

They ignore case and return the first match. Use EXACT inside XLOOKUP or MATCH.

Using SEARCH instead of FIND

SEARCH ignores case. FIND is the case-sensitive one.

FIND without the length check

FIND also matches codes that contain your text, such as Xk7P inside Xk7P2. Add LEN(range)=LEN(value).

Removing "duplicates" that differ only in case

Remove Duplicates and UNIQUE treat case variants as the same. Check with EXACT before deleting anything.

FAQ

Is VLOOKUP case-sensitive?

No. VLOOKUP, HLOOKUP, XLOOKUP, MATCH, COUNTIF and SUMIF all ignore case. Use EXACT or FIND when case matters.

How do I do a case-sensitive XLOOKUP?

=XLOOKUP(TRUE,EXACT(lookup_range,value),return_range). EXACT turns the lookup range into TRUE/FALSE values and XLOOKUP finds the first TRUE.

How do I check if two cells match exactly, including case?

Use =EXACT(A2,B2). It returns TRUE only when every character, including upper and lower case, is the same. A2=B2 ignores case.

Can COUNTIF be case-sensitive?

No. Use =SUMPRODUCT(--EXACT(range,value)) to count exact-case matches instead.

Functions used

Related guides

Updated