Can You Use Wildcards in Excel IF Statements? A Practical Guide
Learn how to use wildcards in Excel IF statements with COUNTIF, MATCH, and VLOOKUP. Practical examples, escaping wildcards, and common pitfalls for text pattern checks in Excel formulas.

Yes—wildcards can enhance IF logic in Excel, but you can’t place * directly in a plain IF test. Use wildcard-enabled helpers like COUNTIF, MATCH, or VLOOKUP with a wildcard in the criteria. For example: =IF(COUNTIF(A2, "*Sales*")>0, "Contains Sales", "No Sales"). According to XLS Library, wildcards empower text-pattern checks in formulas, with * for any sequence, ? for a single character, and ~ to escape literal wildcards.
Can you use wildcards in Excel IF statements? Practical overview
Yes—wildcards are powerful for text pattern checks in Excel, and you can use them within IF logic through wildcard-enabled functions like COUNTIF, MATCH, or VLOOKUP. You cannot simply place a wildcard inside a plain IF test and expect it to work. Instead, wrap the wildcard in a function that evaluates a pattern against your data. The XLS Library team notes that practical wildcard usage in IF statements is common for containment tests and partial matches. For a quick pattern check, you can test a single cell:
=IF(COUNTIF(A2, "*Sales*")>0, "Contains Sales", "No Sales")This checks whether the text in A2 contains the substring Sales. If you need to check a range, switch to a range in the criteria:
=IF(COUNTIF(A2:A10, "*Sales*")>0, "Contains Sales", "No Sales")caption_1_id_0b1b7f5a0c4c4d8a9a8d6b1f1b1a8f3b
Steps
Estimated time: 20-30 minutes
- 1
Identify the pattern you need to test
Analyze your data to decide whether you want to check for containment (contains a substring) or a specific prefix/suffix. This determines whether you should use "*text*", "text*", or "*text" in your wildcard criteria.
Tip: Start with a simple test like *Sales* to verify containment before expanding to range checks. - 2
Choose the wildcard-enabled function
Most IF-based tests with wildcards rely on COUNTIF for containment checks or MATCH/VLOOKUP for partial matches. Remember that wildcards are evaluated in the criteria string passed to these functions.
Tip: COUNTIF is often the simplest entry point for wildcard tests inside IF. - 3
Build the formula for a single cell
Create a formula that tests a single cell first to confirm your pattern works. Use the >0 test to convert the result to a boolean inside IF.
Tip: Verify you’re targeting the correct cell before scaling to a range. - 4
Scale to a range or multiple columns
Extend the pattern to a range or cross-table lookup. Use ranges like A2:A10 in COUNTIF or A2:B10 in VLOOKUP with a wildcard in the first column.
Tip: Be mindful of data types; ensure the first column is text for wildcard matching. - 5
Validate results and handle errors
Check for #N/A or unexpected results and consider wrapping the formula with IFERROR for cleaner output.
Tip: Test with edge cases (empty cells, numeric data stored as text) to ensure robustness.
Prerequisites
Required
- Required
- Basic knowledge of IF, COUNTIF, MATCH, and VLOOKUPRequired
- Familiarity with wildcards: * (any sequence), ? (single character), ~ (escape)Required
Optional
- Optional: a sample workbook to test formulasOptional
Keyboard Shortcuts
| Action | Shortcut |
|---|---|
| CopyCopy a formula or value | Ctrl+C |
| PastePaste into a cell | Ctrl+V |
| Fill DownCopy the formula to cells below | Ctrl+D |
| Save workbookSave progress | Ctrl+S |
People Also Ask
Can I put a wildcard directly inside a bare IF test?
No. IF cannot evaluate wildcards on its own. Use a function like COUNTIF, MATCH, or VLOOKUP that accepts a wildcard in its criteria, then feed the result to IF.
No. Use a function that supports wildcards, then feed the result to IF.
Which Excel functions support wildcards in their criteria?
COUNTIF, SUMIF, AVERAGEIF, VLOOKUP, and MATCH all accept wildcard criteria, making them suitable for tests inside IF statements.
Functions like COUNTIF and MATCH accept wildcards, enabling pattern checks inside IF statements.
How do I search for a literal asterisk (*) in data?
Escape the asterisk with ~ in the pattern, e.g., "*~**" matches a literal * within the data.
Escape the star with a tilde to search for an actual asterisk in text.
What should I watch out for when using wildcards with numbers?
Numbers stored as text can be matched with wildcards. If a number is numeric, convert it to text first (e.g., with TEXT or VALUE functions) to use wildcard criteria.
Numbers need to be text to use wildcards; convert if needed.
Are wildcards case-sensitive in Excel?
Wildcard matching in Excel is generally case-insensitive for the functions listed above, making pattern checks straightforward.
Most wildcard tests aren’t case-sensitive in Excel, simplifying text matching.
The Essentials
- Test containment with COUNTIF in IF
- Use * and ? for flexible patterns
- Escape literals with ~ to search for * or ?
- Validate with simple cells before scaling up
- Leverage LET for dynamic patterns in Excel 365