Watch Video on Excel Wildcard Characters
There are only 3 Excel wildcard characters (asterisk, question mark, and tilde) and a lot can be done using these.
In this tutorial, I will show you four examples where these Excel wildcard characters are absolute lifesavers.
Excel Wildcard Characters – An Introduction
Wildcards are special characters that can take any place of any character (hence the name – wildcard).
There are three wildcard characters in Excel:
- * (asterisk) – It represents any number of characters. For example, Ex* could mean Excel, Excels, Example, Expert, etc.
- ? (question mark) – It represents one single character. For example, Tr?mp could mean Trump or Tramp.
- ~ (tilde) – It is used to identify a wildcard character (~, *, ?) in the text. For example, let’s say you want to find the exact phrase Excel* in a list. If you use Excel* as the search string, it would give you any word that has Excel at the beginning followed by any number of characters (such as Excel, Excels, Excellent). To specifically look for excel*, we need to use ~. So our search string would be excel~*. Here, the presence of ~ ensures that excel reads the following character as is, and not as a wildcard.
Note: I have not come across many situations where you need to use ~. Nevertheless, it is a good to know feature.
Now let’s go through four awesome examples where wildcard characters do all the heavy lifting.
Excel Wildcard Characters – Examples
Now let’s look at four practical examples where Excel wildcard characters can be mighty useful:
- Filtering data using a wildcard character.
- Partial Lookup using wildcard character and VLOOKUP.
- Find and Replace Partial Matches.
- Count Non-blank cells that contain text.
#1 Filter Data using Excel Wildcard Characters
Excel wildcard characters come in handy when you have huge data sets and you want to filter data based on a condition.
Suppose you have a dataset as shown below:
You can use the asterisk (*) wildcard character in data filter to get a list of companies that start with the alphabet A.
Here is how to do this:
- Select the cells that you want to filter.
- Go to Data –> Sort and Filter –> Filter (Keyboard Shortcut – Control + Shift + L).
- Click on the filter icon in the header cell
- In the field (below the Text Filter option), type A*
- Click OK.
This will instantly filter the results and give you 3 names – ABC Ltd., Amazon.com, and Apple Stores.
How does it work? – When you add an asterisk (*) after A, Excel would filter anything that starts with A. This is because an asterisk (being an Excel wildcard character) can represent any number of characters.
Now with the same methodology, you can use various criteria to filter results.
For example, if you want to filter companies that begin with the alphabet A and contain the alphabet C in it, use the string A*C. This will give you only 2 results – ABC Ltd. and Amazon.com.
If you use A?C instead, you will only get ABC Ltd as the result (as only one character is allowed between ‘a’ and ‘c’)
Note: The same concept can also be applied when using Excel Advanced Filters.
#2 Partial Lookup Using Wildcard Characters & VLOOKUP
Partial look-up is needed when you have to look for a value in a list and there isn’t an exact match.
For example, suppose you have a data set as shown below, and you want to look for the company ABC in a list, but the list has ABC Ltd instead of ABC.
You can not use the regular VLOOKUP function in this case as the lookup value does not have an exact match.
If you use VLOOKUP with an approximate match, it will give you the wrong results.
However, you can use a wildcard character within VLOOKUP function to get the right results:
Enter the following formula in cell D2 and drag it for other cells:
How does this formula work?
In the above formula, instead of using the lookup value as is, it is flanked on both sides with the Excel wildcard character asterisk (*) – “*”&C2&”*”
This tells excel that it needs to look for any text that contains the word in C2. It could have any number of characters before or after the text in C2.
Hence, the formula looks for a match, and as soon as it gets a match, it returns that value.
3. Find and Replace Partial Matches
Excel Wildcard characters are quite versatile.
You can use it in a complex formula as well as in basic functionality such as Find and Replace.
Suppose you have the data as shown below:
In the above data, the region has been entered in different ways (such as North-West, North West, NorthWest).
This is often the case with sales data.
To clean this data and make it consistent, we can use Find and Replace with Excel wildcard characters.
Here is how to do this:
- Select the data where you want to find and replace text.
- Go to Home –> Find & Select –> Go To. This will open the Find and Replace dialogue box. (You can also use the keyboard shortcut – Control + H).
- Enter the following text in the find and replace dialogue box:
- Find what: North*W*
- Replace with: North-West
- Click on Replace All.
This will instantly change all the different formats and make it consistent to North-West.
How does this Work?
In the Find field, we have used North*W* which will find any text that has the word North and contains the alphabet ‘W’ anywhere after it.
Hence, it covers all the scenarios (NorthWest, North West, and North-West).
Find and Replace finds all these instances and changes it to North-West and makes it consistent.
4. Count Non-blank Cells that Contain Text
I know you are smart and you thinking that Excel already has an inbuilt function to do this.
You’re absolutely right!!
This can be done using the COUNTA function.
BUT… There is one small problem with it.
A lot of times when you import data or use other people’s worksheet, you will notice that there are empty cells while that might not be the case.
These cells look blank but have =”” in it. The trouble is that the
The trouble is that the COUNTA function does not consider this as an empty cell (it counts it as text).
See the example below:
In the above example, I use the COUNTA function to find cells that are not empty and it returns 11 and not 10 (but you can clearly see only 10 cells have text).
The reason, as I mentioned, is that it doesn’t consider A11 as empty (while it should).
But that is how Excel works.
The fix is to use the Excel wildcard character within the formula.
Below is a formula using the COUNTIF function that only counts cells that have text in it:
This formula tells excel to count only if the cell has at least one character.
In the ?* combo:
- ? (question mark) ensures that at least one character is present.
- * (asterisk) makes room for any number of additional characters.
Note: The above formula works when only have text values in the cells. If you have a list that has both text as well as numbers, use the following formula:
Hope these examples give you a flair of the versatility and power of Excel wildcard characters.
If you have any other innovative way to use it, do share it with me in the comments section.
You May Find the Following Excel Tutorials Useful: