Table of Contents
Excel wildcard characters
Asterisk as a wildcard
Question mark as a wildcard
Tilde as a wildcard nullifier
Find and replace wildcards in Excel
How to search with wildcard
How to replace with wildcard
How to find and replace wildcard characters
Filter data with wildcards in Excel
Excel formulas with wildcard
Excel COUNTIF wildcard formula
Excel wildcard VLOOKUP formula
Excel wildcard for numbers
Find and Replace with wildcard number
Filter with wildcard number
Why Excel wildcard not working with numbers in formulas
How to make wildcards work for numbers
Example 1. Excel wildcard formula for numbers
Example 2. Wildcard formula for dates
Practice workbook for download
Home Topics excel Excel wildcard: find and replace, filter, use in formulas with text and numbers

Excel wildcard: find and replace, filter, use in formulas with text and numbers

Mar 31, 2025 pm 02:56 PM

Everything you need to know about wildcards on one page: what they are, how to best use them in Excel, and why wildcards are not working with numbers.

When you are looking for something but not exactly sure exactly what, wildcards are a perfect solution. You can think of a wildcard as a joker that can take on any value. There are only 3 wildcard characters in Excel (asterisk, question mark, and tilde), but they can do so many useful things!

Excel wildcard characters

In Microsoft Excel, a wildcard is a special kind of character that can substitute any other character. In other words, when you do not know an exact character, you can use a wildcard in that place.

The two common wildcard characters that Excel recognizes are an asterisk (*) and a question mark (?). A tilde (~) forces Excel to treat theses as regular characters, not wildcards.

Wildcards come handy in any situation when you need a partial match. You can use them as comparison criteria for filtering data, to find entries that have some common part, or to perform fuzzy matching in formulas.

Asterisk as a wildcard

The asterisk (*) is the most general wildcard character that can represent any number of characters. For example:

  • ch* - matches any word that begins with "ch" such as Charles, check, chess, etc.
  • *ch - substitutes any text string that ends with "ch" such as March, inch, fetch, etc.
  • *ch* - represents any word that contains "ch" in any position such as Chad, headache, arch, etc.

Question mark as a wildcard

The question mark (?) represents any single character. It can help you get more specific when searching for a partial match. For example:

  • ? - matches any entry containing one character, e.g. "a", "1", "-", etc.
  • ?? - substitutes any two characters, e.g. "ab", "11", "a*", etc.
  • ???-??? - represents any string containing 2 groups of 3 characters separated with a hyphen such as ABC-DEF, ABC-123, 111-222, etc.
  • pri?e - matches price, pride, prize, and the like.

Tilde as a wildcard nullifier

The tilde (~) placed before a wildcard character cancels the effect of a wildcard and turns it into a literal asterisk (~*), a literal question mark (~?), or a literal tilde (~~). For example:

  • *~? - finds any entry ending with question mark, e.g. What?, Anybody there?, etc.
  • *~** - finds any data containing an asterisk, e.g. *1, *11*, 1-Mar-2020*, etc. In this case, the 1st and 3rd asterisks are wildcards, while the second one denotes a literal asterisk character.

Find and replace wildcards in Excel

The uses of wildcard characters with Excel's Find and Replace feature are quite versatile. The following examples will discuss a few common scenarios and warn you about a couple of caveats.

How to search with wildcard

By default, the Find and Replace dialog is configured to look for the specified criteria anywhere in a cell, not to match the entire cell contents. For example, if you use "AA" as your search criteria, Excel will return all the entries containing it such as AA-01, 01-AA, 01-AA-02, and so on. That works great in most situations, but under certain circumstances can be a complication.

In the below dataset, supposing you want to find the IDs that consist of 4 characters separated with a hyphen. So, you open the Find and Replace dialog (Ctrl F), type ??-?? in the Find what box, and press Find All. The result looks a bit perplexing, isn't it?

Excel wildcard: find and replace, filter, use in formulas with text and numbers

Technically, strings like AAB-01 or BB-002 also match the criteria because they do contain a ??-?? substring. To exclude these from the results, click the Options button, and check the Match entire cell contents box. Now, Excel will limit the results to only the ??-?? strings:

Excel wildcard: find and replace, filter, use in formulas with text and numbers

How to replace with wildcard

In case your data contains some fuzzy matches, wildcards can help you quickly locate and unify them.

In the screenshot below, you can see two spelling variations of the same city Homel and Gomel. We'd like to replace both with another version - Homyel. (And yes, all three spellings of my native city are correct and generally accepted :)

To replace partial matches, this is what you need to do:

  1. Press Ctrl H to open the Replace tab of the Find and Replace dialog.
  2. In the Find what box, type the wildcard expression: ?omel
  3. In the Replace with box, type the replacement text: Homyel
  4. Click the Replace All button.

Excel wildcard: find and replace, filter, use in formulas with text and numbers

And observe the results:

Excel wildcard: find and replace, filter, use in formulas with text and numbers

How to find and replace wildcard characters

To find a character that Excel recognizes as a wildcard, i.e. a literal asterisk or question mark, include a tilde (~) in your search criteria. For example, to find all the entries containing asterisks, type ~* in the Find what box:

Excel wildcard: find and replace, filter, use in formulas with text and numbers

If you'd like to replace the asterisks with something else, switch to the Replace tab and type the character of interest in the Replace with box. To remove all the found asterisk characters, leave the Replace with box empty, and click Replace all.

Excel wildcard: find and replace, filter, use in formulas with text and numbers

Filter data with wildcards in Excel

Excel wildcards also come very useful when you have a huge column of data and wish to filter that data based on condition.

In our sample data set, supposing you want to filter the IDs beginning with "B". For this, do the following:

  1. Add filter to the header cells. The fastest way is to press the Ctrl Shift L shortcut.
  2. In the target column, click the filter drop-down arrow.
  3. In the Search box, type your criteria, B* in our case.
  4. Click OK.

This will instantly filter the data based on your wildcard criteria like show below:

Excel wildcard: find and replace, filter, use in formulas with text and numbers

Wildcards can also be used with Advanced Filter, which could make it a nice alternative to regular expressions (also called regexes by tech gurus) that Excel does not support. For more information, please see Excel Advanced Filter with wildcards.

Excel formulas with wildcard

First off, it should be noted that quite a limited number of Excel functions support wildcards. Here is a list of the most popular functions that do with formula examples:

AVERAGEIF with wildcards - finds the average (arithmetic mean) of the cells that meet the specified condition.

AVERAGEIFS - returns the average of the cells that meet multiple criteria. Like AVERAGEIF in the above example allows wildcards.

COUNTIF with wildcard characters - counts the number of cells based on one criterion.

COUNTIFS with wildcards - counts the number of cells based on multiple criteria.

SUMIF with wildcard- sums cells with condition.

SUMIFS - adds cells with multiple criteria. Like SUMIF in the above example accepts wildcard characters.

VLOOKUP with wildcards - performs a vertical lookup with partial match.

HLOOKUP with wildcard - does a horizontal lookup with partial match.

XLOOKUP with wildcard characters - performs a partial match lookup both in a column and a row.

MATCH formula with wildcards - finds a partial match and returns its relative position.

XMATCH with wildcards - a modern successor of the MATCH function that also supports wildcard matching.

SEARCH with wildcards - unlike the case-sensitive FIND function, case-insensitive SEARCH understands wildcard characters.

If you need to do partial matching with other functions that do not support wildcards, you will have to figure out a workaround like Excel IF wildcard formula.

The following examples demonstrate some general approaches to using wildcards in Excel formulas.

Excel COUNTIF wildcard formula

Let's say you wish to count the number of cells containing the text "AA" in the range A2:A12. There are three ways to accomplish this.

The easiest one is to include wildcard characters directly in the criteria argument:

=COUNTIF(A2:A12, "*AA*")

In practice, such "hardcoding" is not the best solution. If the criteria changes at a later point, you'll have to edit your formula every time.

Instead of typing the criteria in the formula, you can input it in some cell, say E1, and concatenate the cell reference with the wildcard characters. Your complete formula would be:

=COUNTIF(A2:A12,"*"&E1&"*")

Excel wildcard: find and replace, filter, use in formulas with text and numbers

Alternatively, you can input a wildcard string (*AA* in our example) in the criteria cell (E1) and include only the cell reference in the formula:

=COUNTIF(A2:A12, E1)

Excel wildcard: find and replace, filter, use in formulas with text and numbers

All three formulas will produce the same result, so which one to use is a matter of your personal preference.

Note. The wildcard search is not case sensitive, so the formula counts both upper case and lowercase characters like AA-01 and aa-01.

Excel wildcard VLOOKUP formula

When you need to look for a value that does not have an exact match in the source data, you can use wildcard characters to find a partial match.

In this example, we are going to look up the IDs that start with specific characters, and return their prices from column B. To have it done, enter the unique parts of the targets IDs in cells D2, D3 and D4 and use this formula to get the results:

=VLOOKUP(D2&"*", $A$2:$B$12, 2, FALSE)

The above formula goes to E1, and due to the clever use of relative and absolute cells references it copies correctly to the below cells.

Excel wildcard: find and replace, filter, use in formulas with text and numbers

Note. As the Excel VLOOKUP function returns the first found match, you should be very careful when searching with wildcards. If your lookup value matches more than one value in the lookup range, you may get misleading results.

Excel wildcard for numbers

It is sometimes stated that wildcards in Excel only work for text values, not numbers. However, this is not exactly true. With the Find and Replace feature as well as Filter, wildcards work fine for both text and numbers.

Find and Replace with wildcard number

In the screenshot below, we are using *4* for the search criteria to search for the cells containing the digit 4, and Excel finds both text strings and numbers:

Excel wildcard: find and replace, filter, use in formulas with text and numbers

Filter with wildcard number

Likewise, Excel's auto-filter has no problem with filtering numbers containing "4":

Excel wildcard: find and replace, filter, use in formulas with text and numbers

Why Excel wildcard not working with numbers in formulas

Wildcards with numbers in formulas is a different story. Using wildcard characters together with numbers (no matter whether you surround the number with wildcards or concatenate a cell reference) converts a numeric value into a text string. As the result, Excel fails to recognize a string in a range of numbers.

For instance, both of the below formulas count the number of strings containing "4" perfectly well:

=COUNTIF(A2:A12, "*4*" )

=COUNTIF(A2:A12, "*"&E1&"*" )

Excel wildcard: find and replace, filter, use in formulas with text and numbers

But neither can identify digit 4 within a number:

Excel wildcard: find and replace, filter, use in formulas with text and numbers

How to make wildcards work for numbers

The easiest solution is to convert numbers to text (for example, by using the Text to Columns feature) and then do a regular VLOOKUP, COUNTIF, MATCH, etc.

For instance, to get the count of cells that begin with the number in E1, the formula is:

=COUNTIF(B2:B12, E1&"*" )

Excel wildcard: find and replace, filter, use in formulas with text and numbers

In situation when this approach is not practically acceptable, you will have to work out your own formula for each specific case. Alas, a generic solution does not exist :( Below, you will find a couple of examples.

Example 1. Excel wildcard formula for numbers

This example shows how to count numbers that contain a specific digit. In the sample table below, suppose you want to calculate how many numbers in the range B2:B12 contain "4". Here's the formula to use:

=SUMPRODUCT(--(ISNUMBER(SEARCH("4", B2:B12))))

Excel wildcard: find and replace, filter, use in formulas with text and numbers

How this formula works

Working from the inside out, here's what the formula does:

The SEARCH function looks for the specified digit in every cell of the range and returns its position, a #VALUE error if not found. Its output is the following array:

{#VALUE!;1;#VALUE!;#VALUE!;3;#VALUE!;#VALUE!;1;#VALUE!;#VALUE!;#VALUE!}

The ISNUMBER function takes it from there and changes any number to TRUE and error to FALSE:

{FALSE;TRUE;FALSE;FALSE;TRUE;FALSE;FALSE;TRUE;FALSE;FALSE;FALSE}

A double unary operator (--) coerces TRUE and FALSE to 1 and 0, respectively:

{0;1;0;0;1;0;0;1;0;0;0}

Finally, the SUMPRODUCT function adds up the 1's and returns the count.

Note. When using a similar formula in your worksheets, in no case you should include "$" or any other currency symbol in the SEARCH function. Please remember that this is only a "visual" currency format applied to the cells, the underlying values are mere numbers.

Example 2. Wildcard formula for dates

The SUMPRODUCT formula discussed above works beautifully for numbers but will fail for dates. Why? Because internally Excel stores dates as serial numbers, and the formula would process those numbers, not the dates displayed in cells.

To overcome this obstacle, utilize the TEXT function to convert dates to text strings, and then feed the strings to the SEARCH function.

Depending on exactly what you aim to count, the text formats may vary.

To count all the dates in C2:C12 that have "4" in the day, month or year, use "mmddyyyy":

=SUMPRODUCT(--(ISNUMBER(SEARCH("4",TEXT(C2:C12, "mmddyyyy")))))

Excel wildcard: find and replace, filter, use in formulas with text and numbers

To count only the days that contain "4" ignoring months and years, use the "dd" text format:

=SUMPRODUCT(--(ISNUMBER(SEARCH("4",TEXT(C2:C12, "dd")))))

Excel wildcard: find and replace, filter, use in formulas with text and numbers

That's how to use wildcards in Excel. I hope this information will prove useful in your work. Anyway, I thank you for reading and hope to see you on our blog next week!

Practice workbook for download

Wildcards in Excel formulas (.xlsx file)

The above is the detailed content of Excel wildcard: find and replace, filter, use in formulas with text and numbers. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1242
24
MEDIAN formula in Excel - practical examples MEDIAN formula in Excel - practical examples Apr 11, 2025 pm 12:08 PM

This tutorial explains how to calculate the median of numerical data in Excel using the MEDIAN function. The median, a key measure of central tendency, identifies the middle value in a dataset, offering a more robust representation of central tenden

Excel shared workbook: How to share Excel file for multiple users Excel shared workbook: How to share Excel file for multiple users Apr 11, 2025 am 11:58 AM

This tutorial provides a comprehensive guide to sharing Excel workbooks, covering various methods, access control, and conflict resolution. Modern Excel versions (2010, 2013, 2016, and later) simplify collaborative editing, eliminating the need to m

Google Spreadsheet COUNTIF function with formula examples Google Spreadsheet COUNTIF function with formula examples Apr 11, 2025 pm 12:03 PM

Master Google Sheets COUNTIF: A Comprehensive Guide This guide explores the versatile COUNTIF function in Google Sheets, demonstrating its applications beyond simple cell counting. We'll cover various scenarios, from exact and partial matches to han

Excel: If cell contains formula examples Excel: If cell contains formula examples Apr 09, 2025 am 09:04 AM

This tutorial demonstrates various Excel formulas to check if a cell contains specific values, including text, numbers, or parts of strings. It covers scenarios using IF, ISTEXT, ISNUMBER, SEARCH, FIND, COUNTIF, EXACT, SUMPRODUCT, VLOOKUP, and neste

How to convert Excel to JPG - save .xls or .xlsx as image file How to convert Excel to JPG - save .xls or .xlsx as image file Apr 11, 2025 am 11:31 AM

This tutorial explores various methods for converting .xls files to .jpg images, encompassing both built-in Windows tools and free online converters. Need to create a presentation, share spreadsheet data securely, or design a document? Converting yo

Google sheets chart tutorial: how to create charts in google sheets Google sheets chart tutorial: how to create charts in google sheets Apr 11, 2025 am 09:06 AM

This tutorial shows you how to create various charts in Google Sheets, choosing the right chart type for different data scenarios. You'll also learn how to create 3D and Gantt charts, and how to edit, copy, and delete charts. Visualizing data is cru

Excel RANK function and other ways to calculate rank Excel RANK function and other ways to calculate rank Apr 09, 2025 am 11:35 AM

This Excel tutorial details the nuances of the RANK functions and demonstrates how to rank data in Excel based on multiple criteria, group data, calculate percentile rank, and more. Determining the relative position of a number within a list is easi

How to flip data in Excel columns and rows (vertically and horizontally) How to flip data in Excel columns and rows (vertically and horizontally) Apr 11, 2025 am 09:05 AM

This tutorial demonstrates several efficient methods for vertically and horizontally flipping tables in Excel, preserving original formatting and formulas. While Excel lacks a direct "flip" function, several workarounds exist. Flipping Dat

See all articles