Skip to content

How to case-sensitive lookup in Excel in Excel

Look up a code where upper and lower case matter, using EXACT inside XLOOKUP or INDEX and MATCH, since normal lookups ignore case.

A parts list has the codes ab12, AB12 and Ab12 for three different items. A normal lookup treats them as the same code and returns whichever comes first. You need one that respects case.

VLOOKUP, XLOOKUP and MATCH all ignore case. The fix is EXACT, which compares two texts and returns TRUE only if they match character for character, including case. Give it the wanted code and the whole code column, and it returns a column of TRUE and FALSE with a single TRUE where the case matches.

Then look up that TRUE:

=XLOOKUP(TRUE, EXACT(F2, A2:A9), B2:B9)

The array EXACT(F2, A2:A9) has one entry per row. XLOOKUP finds the first TRUE and returns the item from the same row of B2:B9.

The older equivalent uses INDEX and MATCH:

=INDEX(B2:B9, MATCH(TRUE, EXACT(F2, A2:A9), 0))

In current Excel both work as ordinary formulas. In older versions the MATCH form had to be entered as an array formula with Ctrl+Shift+Enter.

Two cautions. EXACT treats a trailing space as a difference, so "AB12 " will not match "AB12". And EXACT compares values as text, so the number 12 and the text "12" count as equal.

If the lookup might fail, add a fourth argument to XLOOKUP, for example "No exact match". The Lookups track shows more ways to build conditions inside a lookup.

2 ways to do it

1XLOOKUP with EXACT

=XLOOKUP(TRUE,EXACT(F2,A2:A9),B2:B9)

  1. Type =XLOOKUP(TRUE,EXACT(F2,A2:A9),B2:B9).
  2. EXACT compares the code in F2 with every code, honouring case, and produces TRUE or FALSE for each row.
  3. XLOOKUP finds the TRUE and returns the item from the same position in B2:B9.

2INDEX and MATCH with EXACT

=INDEX(B2:B9,MATCH(TRUE,EXACT(F2,A2:A9),0))

  1. MATCH(TRUE,EXACT(F2,A2:A9),0) returns the position of the first exact, case-matching code.
  2. INDEX returns the item from that position.

Try it yourself

Solve it in the sheet. Every answer is checked, with hints if you need them.

Task 1 of 2

In G2, return the item for the code in F2, matching upper and lower case exactly.

Answer in G2.

G2
A
B
C
D
E
F
G
H
1
Code
Item
Code
Item
2
ab12
Red cable
AB12
3
AB12
Blue cable
aB12
4
Ab12
Green cable
5
ZX90
Steel clip
6
zx91
Brass clip
7
QP07
Foam pad
8
qp07
Rubber pad
9
MN55
Wall plug

Learn it properly, one graded sheet at a time.

Logic and text covers this in lesson 8, PROPER, UPPER and LOWER.