Situatie
Solutie
The Wildcards: Asterisk (*) and Question Mark (?)
There are two wildcards in Excel, and knowing their purpose is crucial to understanding how wildcards work overall.
The Asterisk Wildcard: Any Number of Characters
The first of the two wildcards in Microsoft Excel is an asterisk, which represents any number of characters, including no characters.
For example:
- *OK* matches with any cells that contain “OK,” with any number of characters before or after (including no characters).
- OK* matches with any cells that start with “OK,” with any number of characters (including no characters) after, but nothing before.
- *OK matches with any cells that end with “OK,” with any number of characters (including no characters) before.
| Value to Test | Criterion: *OK* | Criterion: OK* | Criterion: *OK |
|---|---|---|---|
| OK | Match | Match | Match |
| Oklahoma | Match | Match | No match |
| Shook | Match | No match | Match |
| Look | Match | No match | No match |
| Looking | Match | No match | No match |
Microsoft Excel’s second wildcard is the question mark, which substitutes any single character.
For example:
- ?OK? matches with any cells that contain a single character before “OK,” and a single character after.
- OK? matches with any cells that contain a single character after “OK”, but nothing before.
- ?OK matches with any cells that contain a single character before “OK”, but nothing after.
You can also use the question mark and asterisk together to find results that have finite numbers of characters in some positions, but any number of characters in others.
For example:
- ??OK* matches with any cells that begin with two characters, then contain “OK,” with any number of characters at the end (including none).
- *OK? matches with any cells that begin with any number of characters (including none), then contain “OK,” and end with one more character.
- ?OK* matches with any cells that begin with a single character, then contain “OK,” and have any number of characters (including none) thereafter.
| Value to Test | Criterion: ??OK* | Criterion: *OK? | Criterion: ?OK* |
|---|---|---|---|
| Took | Match | No match | No match |
| Books | Match | Match | No match |
| Spooky | No match | Match | No match |
| Poky | No match | Match | Match |
| Jokes | No match | No match | Match |
Sometimes, you might actually want to search for question marks and asterisks as characters in their own right in your Excel worksheet. This is where the third wildcard character—the tilde—comes into play: simply place it before the question mark or asterisk to tell Excel you don’t want them to be treated as wildcards.
For example:
- *~? matches with any cells that contain any number of characters (including none) at the start, and a question mark at the end.
- *~?* matches with any cells that contain any number of characters (including none) on either side of a question mark.
- *~*? matches with any cells that start with any number of characters, followed by an asterisk, followed by a single character.
| Value to Test | Criterion: *~? | Criterion: *~?* | Criterion: *~*? |
|---|---|---|---|
| Dinner? | Match | Match | No match |
| ???k | No match | Match | No match |
| D?*y | No match | Match | Match |
Using Wildcards in Searches
One of the most common uses of wildcards in Microsoft Excel is to find characters in a workbook and, if needed, replace them with alternatives
Let’s say you want to find all the homeware products that are for national sale only.
Press Ctrl+F to launch the Find tab of the Find And Replace dialog box, and in the Find What field, type:
*2??A
where
- The asterisk and the number 2 tell Excel to search for cells that start with any number of characters, followed by the number 2. You need to use an asterisk here, since some countries are represented by two letters while others are represented by three.
- The two question marks followed by the letter A tell Excel that the rest of the string must be made up of two characters and the letter A.
Then, when you click “Find All,” you’ll see a list at the bottom of the Find And Replace dialog box that shows any results that match these criteria.
Click any of the results in the Find And Replace dialog box to jump to the corresponding cell in your spreadsheet. Now, let’s say your aim is to return the codes for all clothing products that aren’t restricted to national or international sales only (in other words, codes that contain a country and a three-digit number starting with 1, but don’t end with a letter).
In the Find What field, type:
*1??
However, when you click “Find All,” a product ending in a letter shows up in the result, suggesting there’s something missing from the criteria.
In fact, this happened because part of the erroneous code contains the substring you entered for the query. So, to exclude these and return only the codes that fully match your query, click “Options,” check “Match Entire Cell Contents,” and click “Find All” again.
This time, only the desired results are displayed. This Excel list shows respondents’ all-time favorite soccer players. However, Maradona’s name has been spelled in three different ways, and you want to amend the incorrect ones.














Leave A Comment?