How to If With Wildcards in Excel

Learn multiple Excel methods to if with wildcards with step-by-step examples and practical applications.

excelformulaspreadsheettutorial
11 min read • Last updated: 7/2/2025

How to If With Wildcards in Excel

Why This Task Matters in Excel

When you work with real-world data, you rarely know the exact words, part numbers, or account codes you will receive. Customer service logs, product catalogs, and transaction descriptions all arrive with inconsistent spellings, prefixes, and suffixes. Decision-making still has to happen, though—“if the description mentions refund, escalate to finance,” or “if the item number starts with ABC, apply a 10 percent discount.” Performing these checks manually is slow and error-prone, especially when the data set grows past a few hundred rows.

Excel’s wildcard characters * (any sequence of characters) and ? (any single character) let you match flexible patterns instead of precise strings. Combining wildcards with conditional logic—“if a cell matches a pattern, then do something”—unlocks a powerful, automated workflow. For example, marketing analysts can classify campaign codes that merely contain “-FB-” as Facebook ads, regardless of the remaining code structure. Supply-chain teams can flag SKU numbers ending in “-R” as refurbished stock, even as the main SKU constantly changes.

Because the technique sits at the intersection of text processing, Boolean logic, and decision branching, it also strengthens a user’s foundational Excel skills. Knowing how to “if with wildcards” naturally leads to mastering functions such as COUNTIF, SEARCH, XLOOKUP, FILTER, and the newer dynamic array functions. Conversely, not understanding wildcard logic can result in mismatched lookups, mis-categorized transactions, and financial reports that simply misstate reality. Automated dashboards that depend on consistent classifications will silently break.

From customer support triaging to financial statement mapping, the ability to test flexible text patterns and return an intelligent outcome is indispensable. Excel’s grid, functions, and table tools together create a low-code environment where business users—without waiting for IT—can build robust classification rules, validate incoming data, and feed analytics models. Mastering “if with wildcards” therefore matters not only for day-to-day productivity but also for larger data quality and governance goals.

Best Excel Approach

The most reliable pattern is to wrap a wildcard-capable function such as COUNTIF, SEARCH, or the newer TEXTSPLIT/XLOOKUP inside an IF statement. That way, the wildcard engine performs the pattern match, and IF simply interprets the numeric or Boolean result.

The two mainstream formulas are:

  1. IF combined with COUNTIF (or COUNTIFS) for a single pattern check. COUNTIF supports * and ? directly, so you can count matches, then ask IF whether the count is at least one.
=IF(COUNTIF(A2,"*refund*")>0,"Escalate","OK")
  1. IF combined with SEARCH plus ISNUMBER for case-insensitive contains logic. SEARCH does not use wildcards but can locate a substring anywhere inside a cell. Because SEARCH returns a position number, wrapping it in ISNUMBER safely converts errors to FALSE.
=IF(ISNUMBER(SEARCH("refund",A2)),"Escalate","OK")

COUNTIF is faster on large ranges and naturally handles * at both ends when you want a classic “contains” test. SEARCH is more flexible when you need to embed the pattern inside another formula or when wildcards are not necessary (for example, locating multiple substrings at once with LET).

In older Excel versions (pre-2007) you might prefer FIND (case-sensitive) instead of SEARCH. In Excel 365 you can even return spill arrays with FILTER:

=FILTER(A2:B100,ISNUMBER(SEARCH("refund",A2:A100)))

All approaches start with a clear pattern: decide what constitutes a match, apply a wildcard-capable test, and feed the Boolean or numeric result into IF.

Parameters and Inputs

  • Pattern to match – a text string that may include * or ?. If you store the pattern in a cell, ensure it is formatted as plain text.
  • Range or text to search – the cell, range, or array you want to evaluate. COUNTIF requires a range reference such as [A2:A500]. SEARCH works on a single text input, so you often use it row by row.
  • Logical comparison – COUNTIF returns a count; you compare it to zero (>0). SEARCH returns a number or an error; you wrap it in ISNUMBER.
  • Output values – the “value if true” and “value if false” parameters of IF can be text, numbers, or further calculations.
  • Optional: multiple criteria – COUNTIFS supports several pattern checks simultaneously. Remember each criterion has its own wildcard string.
  • Data preparation – strip leading/trailing spaces with TRIM, ensure consistent case if using FIND, and remove non-printing characters with CLEAN to avoid surprise mismatches.
  • Edge cases – empty cells count as matches when you use a bare *; avoid this by specifying "<>". SEARCH on a blank cell returns an error, so wrap with IFERROR if needed.

Step-by-Step Examples

Example 1: Basic Scenario – Flag Descriptions Containing “Refund”

Imagine column A of a help-desk sheet holds ticket descriptions. You need a column B formula that displays “Escalate” if the description contains the word “refund” in any position.

  1. Sample data
  • A2: “Requesting refund for order 123”
  • A3: “Login issue”
  • A4: “Partial REFUND processed”
  1. Enter the following in B2 and copy down:
=IF(COUNTIF(A2,"*refund*")>0,"Escalate","OK")
  1. Explanation
    COUNTIF sees the pattern *refund*—asterisks on both sides mean “any characters before or after.” Because COUNTIF is not case-sensitive, “REFUND” and “refund” both match. When the count is at least one, IF returns “Escalate.”
  2. Expected results
  • B2: Escalate
  • B3: OK
  • B4: Escalate
  1. Variations
  • To make the test case-sensitive, use FIND with EXACT or switch to SEARCH plus LOWER on both sides.
  • If you want to exclude the word “non-refund,” adapt the pattern to *" refund "* with spaces or add a negative criterion using COUNTIFS.

Troubleshooting tip: If every row shows “Escalate,” verify you did not leave a space character outside the asterisks, which would accidentally match nearly everything.

Example 2: Real-World Application – Classify SKUs by Prefix

A wholesale distributor uses a 10-character SKU where the first three letters designate the product family:

  • “ELE” = Electronics
  • “FUR” = Furniture
  • Anything else = “Other”

Data lives in [A2:A4000]. Column B should display the family name. You also need an inventory value in column C that is increased by 5 percent for Electronics as an import fee.

  1. SKU classifier in B2:
=IF(LEFT(A2,3)="ELE","Electronics",
 IF(LEFT(A2,3)="FUR","Furniture","Other"))
  1. Import fee in C2:
=IF(LEFT(A2,3)="ELE",B2*1.05,B2)

Now let us imagine a subset of SKUs contain hyphens or spaces before the code, such as “ ELE-9083”. Wildcards fix this quickly:

=IF(COUNTIF(A2,"*ELE*"),"Electronics",
 IF(COUNTIF(A2,"*FUR*"),"Furniture","Other"))
  1. Why this solves the business problem
    The warehouse frequently receives files from suppliers with unexpected spaces and dashes. Using COUNTIF with leading and trailing asterisks guarantees the core code is found anywhere inside the string, reducing mis-classification. Downstream, purchasing reports built on the family field remain accurate.

  2. Performance considerations
    COUNTIF across 4000 rows is light, but if the file grows to 50 000 lines, place the SKU prefix in a helper column using =LEFT(A2,3) and do an exact match lookup. Helper columns are often faster than repeated wildcard scanning.

A fintech firm flags transactions that mention any of three sensitive words: “fraud,” “chargeback,” or “dispute.” Instead of repeating SEARCH three times, you can spill a dynamic array with LET for maintainability.

  1. Store the keyword list in [E2:E4].
  2. In D2 (next to each transaction description), enter:
=LET(
 txt, A2,
 kw, TRANSPOSE(E2:E4),
 hit, ISNUMBER(SEARCH(kw,txt)),
 IF(OR(hit),"Review","Clear")
)

Explanation: TRANSPOSE converts the vertical list into a horizontal array so SEARCH can process all keywords simultaneously. SEARCH returns an array of positions or errors; ISNUMBER converts to TRUE/FALSE; OR reduces that to a single TRUE if any keyword matches. Because LET assigns names, the formula remains readable, and you can add or remove keywords by simply editing the spill range [E2:E4].

Performance optimization: For tens of thousands of rows, spill the keyword checks into a separate range and reference them by row, so Excel evaluates SEARCH only once per keyword set instead of per cell per keyword.

Edge-case management: SEARCH is case-insensitive, but if the auditors demand case precision, swap in FIND. If a description is blank, SEARCH throws an error, so wrap the entire LET in IF(A\2=\"\",\"Clear\", …).

Tips and Best Practices

  1. Always place an asterisk on both sides when you mean “contains.” Forgetting an ending * accidentally restricts the match to text that finishes with the pattern.
  2. Store patterns in named ranges like pattern_refund to avoid typos and give non-technical colleagues a place to edit rules without modifying formulas.
  3. Combine helper columns and structured tables. A helper column extracting the first three letters (=LEFT([@SKU],3)) makes wildcard logic easier to audit and speeds calculation.
  4. Use dynamic arrays (FILTER, UNIQUE) to visually audit wildcard hits before embedding inside IF. Seeing the list of rows that match *refund* gives confidence.
  5. Remember COUNTIF treats ? as “any one character.” If your data includes literal question marks, escape them by concatenating ~ in front: "*~?*" matches an actual question mark.
  6. Turn on Manual Calculation when experimenting with multiple wildcard formulas on large data sets, then recalc once after edits to save time.

Common Mistakes to Avoid

  1. Comparing COUNTIF directly to blank: Writing =IF(COUNTIF(A2,"*refund*"),"Yes","No") produces unpredictable results because COUNTIF returns numbers, not Booleans. Always compare >0.
  2. Forgetting case sensitivity with FIND: Users assume FIND acts like SEARCH. FIND will miss “Refund” if the pattern is “refund”. Either convert both sides with LOWER or use SEARCH.
  3. Overusing wildcards: A pattern of *a*e* is too broad and may match most strings. Tighten the pattern or combine criteria with COUNTIFS.
  4. Not escaping special characters: Stars, question marks, and tildes themselves need escapes (~*, ~?, ~~) inside patterns. Otherwise the engine treats them as wildcards.
  5. Leaving trailing spaces in pattern cells: A pattern cell containing “refund ” with a space at the end will silently fail. Use TRIM on pattern inputs or check length with LEN.

Alternative Methods

MethodFunctions UsedProsConsBest For
IF + COUNTIFIF, COUNTIFFast on ranges, native wildcard support, simple syntaxCannot do case-sensitive matches, one pattern per function unless using COUNTIFSClassic contains checks on large lists
IF + SEARCH/ISNUMBERIF, ISNUMBER, SEARCHCase-insensitive, works on single cells, flexible for dynamic arraysSlightly slower row-by-row, wildcards not supported, returns errors on blanksRow-level checks with additional string logic
IF + FINDIF, ISNUMBER, FINDCase-sensitive containsMisses matches with different case, same error handling as SEARCHAudits requiring exact case
SWITCH/XLOOKUP with WildcardsSWITCH, XLOOKUPCleaner nested logic, easier maintenance as rules growRequires Excel 365, learning curveReplacing complex nested IF trees
Power QueryM language pattern matchesHandles millions of rows, no formula burden on workbook, reusable stepsRefresh cycle required, not instantaneous, separate UIPeriodic ETL jobs, data warehouse feeds

Use COUNTIF for speed and simplicity, SEARCH for flexibility, and Power Query when the volume eclipses worksheet limits.

FAQ

When should I use this approach?

Deploy “if with wildcards” whenever the exact text may vary yet you still need deterministic decisions—classifying logs, routing emails, or tagging revenue lines.

Can this work across multiple sheets?

Yes. With COUNTIF you reference external sheets: =IF(COUNTIF(Sheet2!A:A,"*refund*")>0,…). For SEARCH-based tests, index the other sheet’s cell directly (=IF(ISNUMBER(SEARCH("refund",Sheet2!A2)),…)). Remember to include the sheet name inside single quotes if it contains spaces.

What are the limitations?

COUNTIF cannot perform case-sensitive matches; FIND cannot process wildcards; SEARCH throws errors on blank cells. Very large wildcard scans can slow recalculation.

How do I handle errors?

Wrap SEARCH or FIND inside IFERROR: =IF(IFERROR(SEARCH("refund",A2),0),"Escalate","OK"). For COUNTIF, blank cells are safe—the count is zero—but confirm your pattern does not wrongly match blank criteria like *.

Does this work in older Excel versions?

COUNTIF and SEARCH have been around since Excel 97, so the basic formulas work everywhere. Dynamic arrays (FILTER, LET) require Excel 365/2021.

What about performance with large datasets?

Place patterns in helper columns, avoid volatile functions, and consider converting the range to an Excel Table so formulas auto-fill without array references. For files above roughly 100 000 rows, Power Query or a database may be faster.

Conclusion

Mastering “if with wildcards” lets you interrogate messy, real-world text in a clean, automated way. By combining IF with COUNTIF, SEARCH, or their modern dynamic-array counterparts, you classify, flag, and transform data at scale without writing a single macro. The skill dovetails naturally into lookups, data cleansing, and dashboarding, positioning you for deeper Excel power such as array formulas and Power Query. Practice on small datasets, then integrate the technique into larger workflows—your future self (and your teammates) will thank you when reports update in seconds, not hours.

We use tracking cookies to understand how you use the product and help us improve it. Please accept cookies to help us improve.