Lesson 75 of 92 · Free Excel Course
Excel · Excel function reference
Excel EXACT Function: Syntax, Examples and Common Errors
The Excel EXACT function compares two texts case-sensitively. Syntax, Microsoft's example, case-sensitive COUNT and XLOOKUP, and a free workbook.
The EXACT function checks whether two pieces of text are exactly the same, down to every capital letter and every space. It returns TRUE when they match and FALSE when they don't. That makes it the tool for jobs where "ab-100" and "AB-100" are different things: product codes, passwords, IDs and anything else where case matters. Microsoft notes that EXACT is case-sensitive but ignores formatting. It works in Excel for Microsoft 365 (Windows and Mac), Excel for the web, and Excel 2024, 2021, 2019 and 2016.
Syntax
=EXACT(text1, text2)
- text1 (required): the first text to compare. Type it in quotes, like
"word", or point to a cell. - text2 (required): the second text. Same rules.
There are no optional arguments. Order doesn't matter: EXACT(A2,B2) gives the same answer as EXACT(B2,A2). You can also give EXACT numbers; it compares them as text, which is why formatting makes no difference.
Examples
1. Microsoft's example. This is the example from Microsoft's EXACT page: three pairs of words, compared in column C.
| A | B | C | |
|---|---|---|---|
| 1 | Text1 | Text2 | EXACT |
| 2 | word | word | TRUE |
| 3 | Word | word | FALSE |
| 4 | w ord | word | FALSE |
2. EXACT versus the = sign. The = sign also returns TRUE or FALSE, so why not use it? Because it ignores case. Here column C uses =A2=B2 and column D uses EXACT.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Typed | Expected | = sign | EXACT |
| 2 | AB-100 | AB-100 | TRUE | TRUE |
| 3 | ab-100 | AB-100 | TRUE | FALSE |
| 4 | AB-100 | AB-100 | FALSE | FALSE |
| 5 | $1,250.00 | 1250 | TRUE | TRUE |
Row 4 is worth remembering. A trailing space is invisible in the cell, but EXACT (and LEN) will expose it, which helps explain why a lookup "can't find" a value you can see.
3. Count case-sensitive matches. COUNTIF ignores case, so it counts AB-100, ab-100 and Ab-100 alike. To count only the capital version, let EXACT test every cell and add up the TRUEs.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Code | Qty | Count | Result | |
| 2 | AB-100 | 12 | COUNTIF | 4 | |
| 3 | ab-100 | 5 | Case-sensitive count | 2 | |
| 4 | Ab-100 | 8 | Case-sensitive sum | 19 | |
| 5 | AB-100 | 3 | |||
| 6 | CD-200 | 20 | |||
| 7 | AB-100 | 7 |
EXACT returns six TRUE/FALSE values here, the double minus (--) turns them into 1s and 0s, and SUMPRODUCT adds them. Notice COUNTIF gives 4, not 5: it also misses the code with the trailing space in A5.
4. Case-sensitive lookup with XLOOKUP. XLOOKUP ignores case too, so =XLOOKUP("ab-100",A2:A7,B2:B7) returns 12, the quantity for the first AB-100. The trick is to look up TRUE in the list of EXACT results instead:
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Code | Qty | Lookup | Qty found | |
| 2 | AB-100 | 12 | XLOOKUP (ignores case) | 12 | |
| 3 | ab-100 | 5 | XLOOKUP + EXACT | 5 | |
| 4 | Ab-100 | 8 | |||
| 5 | AB-100 | 3 | |||
| 6 | CD-200 | 20 | |||
| 7 | AB-100 | 7 |
XLOOKUP needs Excel for Microsoft 365, 2021, 2024 or Excel for the web. In older versions, =INDEX(B2:B7,MATCH(TRUE,EXACT(A2:A7,"ab-100"),0)) does the same job; in Excel 2019 and earlier, confirm it with Ctrl+Shift+Enter. Lookups in general are covered in XLOOKUP and INDEX/MATCH.
5. Allow only capital letters with data validation. EXACT can stop people typing a code in the wrong case.
- Select the cell or cells, for example B2:B20.
- On the Data tab, click Data Validation.
- Under Allow, choose Custom.
- In Formula, type
=EXACT(B2,UPPER(B2))(use the top-left cell of your selection) and click OK.
Now typing ab-100 brings up an error, while AB-100 is accepted. UPPER makes a capitalized copy, and EXACT checks the entry already equals it. Avoid the PROPER version of this rule for names: it rejects real names like McDonald. More rules are in drop-down lists and data validation.
Common errors
- FALSE when the text looks identical. Almost always a hidden space or character. Check both cells with
=LEN(A2); if the lengths differ, use=EXACT(TRIM(A2),TRIM(B2)). Text pasted from web pages often contains non-breaking spaces, which TRIM doesn't remove: swap them for normal spaces first with=SUBSTITUTE(A2,CHAR(160)," "). For other non-printing characters, see CLEAN. - TRUE when you expected FALSE. EXACT ignores formatting, so 1250 and $1,250.00 match, and it compares numbers as text, so the number 1250 also matches the text "1250". If the type matters, add
ISNUMBERorISTEXTto the test. - Wrong count or lookup result. You used COUNTIF, MATCH or plain XLOOKUP, which ignore case. Switch to the SUMPRODUCT or XLOOKUP(TRUE,...) patterns above.
- #N/A from XLOOKUP(TRUE,EXACT(...)). No cell matched exactly. Add a fourth argument, such as
"Not found", to show a message instead. - #NAME? XLOOKUP isn't available in your version (Excel 2019 or 2016). Use the INDEX/MATCH version.
- A single TRUE or FALSE instead of a count, or #VALUE! In Excel 2019 and earlier, a range inside EXACT in a normal formula needs Ctrl+Shift+Enter. SUMPRODUCT handles the range on its own, so it doesn't.
- An error from the input cell. If A2 holds an error such as #N/A, EXACT returns that error. Fix the source cell first.
Related functions
- FIND: finds where text starts, and is case-sensitive like EXACT.
- SEARCH: the same as FIND but ignores case and allows wildcards.
- LEN: counts characters, the quickest way to spot the hidden space behind a FALSE.
- CLEAN: strips non-printing characters before you compare.
- Text functions: the lesson on joining, splitting, trimming and changing case.
Try it yourself
Download the practice workbook. Run Microsoft's example, check each code with EXACT, then count and look up the code ab-100 case-sensitively with SUMPRODUCT(--EXACT(...)) and XLOOKUP(TRUE,EXACT(...),...) (1 match, quantity 5, while the ordinary COUNTIF and XLOOKUP say 4 and 12), and add an uppercase-only validation rule. Check yourself against the Answers sheet.
Frequently asked questions
What is the difference between EXACT and the = sign in Excel?
Both compare two values, but the = sign ignores capital letters: ="Word"="word" returns TRUE. =EXACT("Word","word") returns FALSE because EXACT is case-sensitive. Both treat an extra space as a difference.
Is XLOOKUP case-sensitive?
No. XLOOKUP, VLOOKUP, MATCH and COUNTIF all ignore case, so ab-100 finds AB-100. For a case-sensitive lookup, look up TRUE in an EXACT test: =XLOOKUP(TRUE,EXACT(A2:A7,"ab-100"),B2:B7). XLOOKUP needs Excel for Microsoft 365, Excel 2021 or 2024, or Excel for the web.
How do I count cells with case-sensitive text in Excel?
COUNTIF can't do it, because it ignores case. Use =SUMPRODUCT(--EXACT(A2:A7,"AB-100")). EXACT returns TRUE or FALSE for each cell, the -- turns those into 1s and 0s, and SUMPRODUCT adds them up.
Does the EXACT function ignore spaces?
No. A space at the start, at the end or in the middle counts as a character, so "AB-100 " with a trailing space doesn't match "AB-100". If spaces shouldn't matter, wrap the text in TRIM first: =EXACT(TRIM(A2),"AB-100").