Excel has three wildcard characters. The asterisk * stands for any run of characters, the question mark ? stands for exactly one character, and the tilde ~ makes the next wildcard literal. Type =COUNTIF(A2:A11,"ST*") to count every code that starts with ST. Wildcards work in some functions and are ignored by others, which is where most mistakes begin.
Functions
Excel Wildcard Characters: *, ? and ~ With Examples
Ready to practice?
Apply what you just learned with interactive exercises.
This page uses one stock list to show how each wildcard behaves, which functions accept them (COUNTIF, SUMIF, VLOOKUP, MATCH, XLOOKUP, SEARCH and the Find dialog), which do not (equals, IF, FIND, SUBSTITUTE, FILTER), and how to search for a real asterisk or question mark.
TL;DR
- * matches any number of characters, including none. "ST*" matches ST-101, and also a cell holding only ST.
- ? matches exactly one character. "ST-1??" matches ST-101 but not ST-1 or ST-1001.
- ~ turns the next * or ? into an ordinary character: "*~*" finds cells that contain a real asterisk.
- Wildcards work with text only. They work in COUNTIF, SUMIF and their plural forms, in exact-match VLOOKUP, MATCH with 0, XLOOKUP with match mode 2, SEARCH, and Find and Replace.
- Wildcards are ignored by the equals sign, IF comparisons, FIND, SUBSTITUTE and FILTER. Use COUNTIF or SEARCH inside the formula instead.
Table of Contents
- Sample data: a stationery stock list
- What the three wildcards do
- Starts with, ends with and contains
- Match a fixed number of characters with the question mark
- Wildcards in SUMIF
- Find a real asterisk or question mark with the tilde
- Wildcards in lookups: VLOOKUP, MATCH and XLOOKUP
- SEARCH takes wildcards and FIND does not
- Wildcards in IF, FILTER and SUBSTITUTE
- Wildcards in Find and Replace and filters
- Wildcards compared with the alternatives
- Excel versions
- Common wildcard errors and surprises
- What learners get wrong
- Job scenario: a stock check by code prefix
- Practice
- FAQ
- Sources
Sample data: a stationery stock list
Every example uses this list. Row 1 holds headings and the ten items sit in rows 2 to 11.
| Row | A: SKU | B: Item | C: Qty |
| 2 | ST-101 | Blue pen | 40 |
| 3 | ST-102 | Black pen | 25 |
| 4 | ST-201 | Pencil HB | 60 |
| 5 | ST-202 | Pencil 2B | 35 |
| 6 | NB-110 | Notebook A5 | 18 |
| 7 | NB-111 | Notebook A4 | 12 |
| 8 | NB-9 | Notepad | 20 |
| 9 | FD-300 | File folder | 50 |
| 10 | ST-301 | Stapler* | 9 |
| 11 | ST-302 | Glue stick? | 14 |
What the three wildcards do
| Wildcard | Matches | Example criteria | Matches in the list |
| * | Any number of characters, even zero | "ST*" | All six ST codes |
| ? | Exactly one character | "ST-1??" | ST-101 and ST-102 |
| ~ | Makes the next * or ? literal | "*~*" | Stapler* |
Matching ignores case. "st*" and "ST*" return the same count.
Starts with, ends with and contains
Put the asterisk after the text for "starts with", before it for "ends with", and on both sides for "contains".
Starts with: =COUNTIF(A2:A11,"ST*") returns 6. These are the codes ST-101, ST-102, ST-201, ST-202, ST-301 and ST-302. Add detail to narrow it: =COUNTIF(A2:A11,"NB-1*") returns 2, for NB-110 and NB-111. NB-9 does not match because it has no 1 after the hyphen.
Ends with: =COUNTIF(B2:B11,"*pen") returns 2, for Blue pen and Black pen.
Contains: =COUNTIF(B2:B11,"*pen*") returns 4. That is Blue pen, Black pen, Pencil HB and Pencil 2B. The surprise is the pencils. "Pencil" starts with the letters p-e-n, and matching ignores case, so it matches *pen*. A contains test matches anywhere, so it often catches more than you meant. If you want only the pens, use the ends-with form "*pen", or add a space: "* pen".
A fixed word followed by anything: =COUNTIF(B2:B11,"Pencil *") returns 2. The space before the asterisk means the word Pencil stands alone. And =COUNTIF(B2:B11,"Notebook A?") returns 2, for the A5 and A4 notebooks, because the question mark replaces the digit.
To count every cell with text, =COUNTIF(B2:B11,"*") returns 10. The COUNTIF guide shows more patterns, and the COUNT function guide puts text counting next to number counting.
Match a fixed number of characters with the question mark
Each question mark stands for one character, no more and no less. This makes it good for checking the shape of a code.
=COUNTIF(A2:A11,"??-???") returns 9: two characters, a hyphen and three characters. Every code fits except NB-9, which has only one character after the hyphen.
To check the total length, use that many question marks. A full code like ST-101 is six characters, so =COUNTIF(A2:A11,"??????") returns 9. A four-character pattern finds the odd one out: =COUNTIF(A2:A11,"????") returns 1, for NB-9.
Mix the two wildcards for "at least". "ST-1?*" means the text ST-1, then one character, then anything: at least five characters starting with ST-1. And "?*" means at least one character, which is the way to count cells with visible content and skip cells that hold an empty string.
Remember the difference when you move between the two. "???" is exactly three characters, while "*" is any length. A question mark never matches an empty position.
Wildcards in SUMIF
SUMIF, SUMIFS, AVERAGEIF, COUNTIFS, MAXIFS and MINIFS read wildcards in their criteria the same way COUNTIF does.
=SUMIF(A2:A11,"NB*",C2:C11) adds the quantity of every notebook-family code and returns 50 (18 + 12 + 20). To restrict it to three-digit codes, use =SUMIF(A2:A11,"NB-???",C2:C11), which returns 30 because NB-9 is excluded.
For the stationery family, =SUMIF(A2:A11,"ST*",C2:C11) returns 183: 40 + 25 + 60 + 35 + 9 + 14. The SUMIF guide covers the rest of the function.
With two conditions, wildcards go in either one. The COUNTIFS guide has examples such as "*Cape" next to a number test.
Find a real asterisk or question mark with the tilde
What if the data really contains an asterisk? In the list, B10 reads Stapler* and B11 reads Glue stick?. If you search with a plain asterisk, it matches everything. The tilde fixes that: it tells Excel that the next character is an ordinary one.
- =COUNTIF(B2:B11,"*~*") returns 1. Read it as: anything, then a real asterisk, then anything. Only Stapler* matches.
- =COUNTIF(B2:B11,"*~?") returns 1. Anything, then a real question mark. Only Glue stick? matches.
- =COUNTIF(B2:B11,"Stapler~*") returns 1, because it asks for the exact text Stapler* with a literal asterisk at the end.
To find a real tilde, type two of them: ~~.
The same tilde works in the Find box, in XLOOKUP with match mode 2 and in SEARCH.
Wildcards in lookups: VLOOKUP, MATCH and XLOOKUP
Three lookups accept wildcards, each under a condition.
VLOOKUP needs exact match, which means the last argument is FALSE. =VLOOKUP("*folder",B2:C11,2,FALSE) finds the first item ending in folder and returns its quantity, 50. With approximate match (TRUE), wildcards do not work. The VLOOKUP guide explains the last argument.
MATCH needs match type 0. =MATCH("Pencil*",B2:B11,0) returns 3, the position of Pencil HB in B2:B11. The MATCH guide covers the other match types.
XLOOKUP needs the match mode argument set to 2. =XLOOKUP("*folder",B2:B11,C2:C11,"none",2) returns 50. Without the 2, XLOOKUP matches exactly and treats the asterisk as a normal character, so =XLOOKUP("*folder",B2:B11,C2:C11) returns #N/A. This is the most common XLOOKUP wildcard slip. The XLOOKUP guide lists all the modes.
A lookup returns the first match only. If two items end in folder, you get the first one. Use a more specific pattern, or FILTER with SEARCH, when you need all of them.
SEARCH takes wildcards and FIND does not
SEARCH and FIND both return the position of text inside other text. SEARCH accepts wildcards and ignores case. FIND treats ? and * as ordinary characters and respects case.
=SEARCH("pen",B2) returns 6, because pen starts at the sixth character of Blue pen. =SEARCH("b?ue",B2) returns 1: b, any one character, u, e matches Blue at the start.
=FIND("b?ue",B2) returns #VALUE!. FIND looks for a literal question mark between the b and the u, and finds none. The FIND guide shows when its strictness is useful.
SEARCH gives you a way to test "contains" inside other formulas, because it returns a number when it finds something and an error when it does not. Wrap it in ISNUMBER to get TRUE or FALSE: =ISNUMBER(SEARCH("pen",B2)) returns TRUE for Blue pen.
Wildcards in IF, FILTER and SUBSTITUTE
Wildcards do not work everywhere. A comparison with the equals sign takes the characters literally. =B2="*pen" returns FALSE, even though Blue pen ends in pen. That means IF does not accept wildcards in a test like =IF(B2="*pen","pen","other"). It treats the asterisk as a character, so the formula returns other for Blue pen and for every cell except one that holds exactly the text *pen.
Fix it by moving the wildcard into a function that reads it. =COUNTIF(B2,"*pen")=1 returns TRUE: COUNTIF counts the single cell B2, and the count is 1 when it matches. Or use SEARCH: =IF(ISNUMBER(SEARCH("pen",B2)),"Writing","Other") returns Writing for Blue pen.
FILTER has the same limit. It tests with true or false arrays, not criteria. To filter for a pattern, build the array with SEARCH: =FILTER(A2:A11,ISNUMBER(SEARCH("pen",B2:B11))) returns ST-101, ST-102, ST-201 and ST-202, the four items whose names contain pen. The FILTER guide explains the spill.
SUBSTITUTE replaces literal text, so wildcards do nothing. =SUBSTITUTE(A2,"ST-?","") returns ST-101 unchanged, because SUBSTITUTE looks for the four literal characters S, T, hyphen and question mark in a row, and they are not there. See the SUBSTITUTE guide for real replacements. If you need a pattern replace, the newer regex functions in the regex guide are the answer.
Wildcards in Find and Replace and filters
The Find and Replace dialog reads wildcards. On Windows, press Ctrl+H, type ST-1?? in the Find what box, and Find All lists the two matching cells. The same works for Replace: the Replace with box takes plain text, not wildcards.
To search for a real asterisk in the dialog, type ~*. Without the tilde, the dialog lists every cell. On a Mac, use Edit, Find, Replace.
AutoFilter text filters read wildcards too. Open the filter arrow, choose Text Filters, then Custom Filter, and use * or ? in the box. The built-in Begins With, Ends With and Contains choices are the same thing without typing the wildcard.
Wildcards compared with the alternatives
| Need | Wildcard approach | Alternative |
| Count cells that start with text | COUNTIF(range,"ST*") | SUMPRODUCT(--(LEFT(range,2)="ST")) |
| Check the shape of a code | COUNTIF(range,"??-???") | LEN with LEFT and MID |
| Contains test inside IF | Not possible with equals | ISNUMBER(SEARCH(...)) |
| Return a value for a partial name | XLOOKUP mode 2, VLOOKUP exact | INDEX and MATCH with a helper column |
| Replace by pattern | Not possible with SUBSTITUTE | Regex functions, or Find and Replace |
| Complex patterns, such as digits only | Not possible | Regex functions |
Excel versions
Wildcards in COUNTIF, SUMIF, VLOOKUP, MATCH and SEARCH work in every version of Excel, on Windows, Mac and the web. XLOOKUP with match mode 2 needs Microsoft 365, Excel 2021 or Excel for the web. In Excel 2019 and earlier, use INDEX and MATCH with a 0 match type instead. FILTER needs the same newer versions, but the SEARCH trick inside it works the same way.
Common wildcard errors and surprises
| What you see | Cause | Fix |
| =XLOOKUP("*folder",B2:B11,C2:C11) returns #N/A | Match mode 2 is missing, so the asterisk is taken literally | Add ,"none",2 as the last arguments |
| =FIND("b?ue",B2) returns #VALUE! | FIND does not read wildcards | Use SEARCH |
| =B2="*pen" is FALSE | The equals sign compares literally | Use COUNTIF(B2,"*pen")=1 or SEARCH |
| =COUNTIF(C2:C11,"4*") returns 0 | The values are numbers, not text | Convert to text, or use a number condition |
| *pen* counts too many | The text matches inside other words, such as Pencil | Tighten the pattern: "*pen" or "* pen" |
| Searching for * lists everything | The asterisk is a wildcard | Search for ~* |
| A wildcard lookup returns the wrong row | Lookups return the first match | Make the pattern more specific |
| The result is 0 and you can see matches | Trailing spaces in the data | Add an asterisk at the end or clean with TRIM |
What learners get wrong
Between 26 September and 3 November 2026, learners made 928 first attempts across our Wildcard Characters lesson, and 80.4% were right. A first attempt is the first check of a screen in a page view, not a person. The lesson is short and most screens ask for a number, so the misses show how people read the question.
Typing the item instead of the count. The opening screen explains that wildcard characters replace text in functions that search for matching text. It had 103 first attempts and 67.0% were right. The answer is the number 1. The most common wrong answer, 13 first attempts, was a fruit name from the list, where the screen wanted how many fruits match. A match question wants a count.
Treating the pattern as a function. Two first attempts on the same screen invented functions that do not exist, such as =WILDCARD(A:A). Wildcards are not a function. They are characters you place inside the criteria of functions that read them, such as COUNTIF.
A missing closing quote. One first attempt typed =COUNTIF(A1:A8,"Le?on), with the opening quote but no closing one. Excel will not accept it. Every wildcard pattern needs a quote at each end, and the quotes must be straight, not curly.
FIND for a wildcard. On the screen asking how many fruits match *pple, 94 first attempts and 67.0% were right, and the answer is 2. One attempt typed =FIND("*pple",A:A). FIND does not read wildcards, so it hunts for a literal asterisk, and it returns positions, not a count. For a count, use COUNTIF.
Counting characters. The screen on ????? had 87 first attempts, and 78.2% were right. The answer is 3. Five question marks mean exactly five characters, so only five-letter fruit names match. Count the letters in each name, not the items on the list. The screen that introduces the asterisk, which matches any length including none, did about as well, with 78.4% of 97 first attempts right.
Job scenario: a stock check by code prefix
Your supervisor asks for a quick check of the stationery shelf before the weekly order.
- How many ST codes exist? =COUNTIF(A2:A11,"ST*") returns 6.
- How many units are on the shelf for ST codes? =SUMIF(A2:A11,"ST*",C2:C11) returns 183.
- Is any code the wrong length? =COUNTIF(A2:A11,"??????") returns 9, and there are 10 rows. One code is the wrong length. =COUNTIF(A2:A11,"????") returns 1, which points to NB-9, a short code that someone should check against the supplier list.
- Which items carry a flag? =COUNTIF(B2:B11,"*~*") returns 1, for Stapler*, and =COUNTIF(B2:B11,"*~?") returns 1, for Glue stick?. Both are notes typed into the item name and should move into a comment column.
- How many are on hand for a partial name? =VLOOKUP("*folder",B2:C11,2,FALSE) returns 50 for the file folders.
Practice
Open Practice Lesson 67 and type each pattern rather than reading it. Keep the Excel functions cheat sheet open to see which functions read wildcards.
A drill: copy the stock list into a blank sheet and write the formulas for these without looking. Items that end in A4. Codes with exactly two digits after the hyphen. The total quantity of everything that contains the word note. Then check each one by reading the matching cells yourself.
FAQ
What are the wildcard characters in Excel?
Excel has three: the asterisk, which matches any number of characters; the question mark, which matches exactly one character; and the tilde, which makes a following asterisk or question mark literal. They work inside the criteria of functions such as COUNTIF and SUMIF, and in Find and Replace.
How do I use a wildcard in an Excel formula?
Put the wildcard inside quotes in a function that reads it. For example, =COUNTIF(A2:A11,"ST*") counts every cell starting with ST. The function must support wildcards. COUNTIF, SUMIF, exact-match VLOOKUP, MATCH with 0, XLOOKUP with mode 2 and SEARCH do. The equals sign does not.
How do I find an asterisk in Excel?
Type a tilde before the asterisk. In the Find box, search for ~* to jump to a cell with a real asterisk. In a formula, use =COUNTIF(B2:B11,"*~*") to count cells that contain one. Without the tilde, the asterisk matches everything.
Why does my wildcard not work in IF?
IF compares with the equals sign, and the equals sign reads characters literally. =B2="*pen" is FALSE for Blue pen, even though the name ends in pen. Move the test into a function that reads wildcards, for example =IF(ISNUMBER(SEARCH("pen",B2)),"Writing","Other"), or use COUNTIF on a single cell.
Can I use wildcards in XLOOKUP?
Yes, but only when the match mode argument is 2. =XLOOKUP("*folder",B2:B11,C2:C11,"none",2) finds the first item ending in folder and returns 50. Without the 2, the asterisk is taken literally and the lookup returns #N/A or your own not-found text. XLOOKUP needs a recent Excel version.
Do wildcards work with numbers?
No. Wildcards match text only. A pattern like "4*" will not match the number 40. If you need to match the start of a number, convert it to text first, for example with the TEXT function, or use a numeric condition like ">=40" instead.
What is the difference between SEARCH and FIND for wildcards?
SEARCH reads wildcards and ignores case. FIND treats ? and * as ordinary characters and respects case. Use SEARCH when you want a pattern, and FIND when you need an exact, case-sensitive position. Both return #VALUE! when the text is not found.
Sources
Keep going
Guides people read next.

SQL Data Types: Categories, Examples and How to Choose
SQL data types explained: numeric, text, date and time, Boolean and binary types, with examples, MySQL, SQL Server, Oracle and PostgreSQL differences, and how to choose.
15 min
WEEKDAY Function in Excel: Syntax, Examples and Day Names
Learn how the Excel WEEKDAY function works, which return_type to pick, how to get day names, flag weekends and fix errors, with copy-ready formulas.
15 min
CHOOSECOLS Function in Excel: Syntax, Examples, Fixes
Learn how the Excel CHOOSECOLS function works, with CHOOSEROWS too: syntax, negative indexes, FILTER combos, version support and fixes for #VALUE! and #SPILL!.
16 min