You need to know what the tilde (~) does in Excel

https://www.profitableratecpm.com/f4ffsdxe?key=39b1ebce72f3758345b2155c98e6709c

Imagine this: you need to find or count cells containing asterisks.

or question marks (?) in Excel, but you get incorrect results. This is because asterisks and question marks are wildcards. The solution? Excel’s essential escape character, the tilde (~).

Wildcards and escapes in Excel

Wildcards are symbols that allow you to create flexible search criteria in Excel functions such as COUNTIF or SUMIF, as well as features such as Find & Replace and Filter. However, to use them accurately, you need to know how to use the escape character (the tilde) to search for the wildcards themselves.

Excel wildcards

Excel recognizes two main wildcards: the asterisk and the question mark.

Wildcard

Name

What this represents

Example

*

Asterisk

Any sequence of characters (including no characters).

Searching for “A*” matches “Apple,” “A,” and “Accountant.”

?

Question mark

Any character in this position.

Searching for “b?t” matches “bat”, “bet”, “bit” and “but”, but not “boot”.

The Problem: When Wildcards Hide Literal Characters

If your data contains an actual asterisk or question mark and you try to search for it using a function or feature that supports wildcards, Excel interprets the symbol as its generic meaning, not the literal character.

Imagine you manage inventory for an electronics store. In your product database, you use an asterisk to indicate clearance items.

An Excel database of products, with various items followed by an asterisk.

=COUNTIF(A:A,"*")

You want to know exactly how many products are marked for customs clearance, so in a separate cell you type:

However, the formula counts every non-blank cell in column A because the asterisk is interpreted as

The COUNTIF function with the asterisk wildcard returning the total count of all elements.

The solution: the tilde escape character

=COUNTIF(A:A,"*~*")

To force Excel to treat the asterisk as a literal character rather than a wildcard, you need to add a tilde to the formula:

Here the tilde escapes the second asterisk, treating it as a literal character. The first asterisk is a wildcard, ensuring that the function finds cells containing any number of characters before the asterisk.

The COUNTIF function with the asterisk wildcard negated by the tilde.

The formula now correctly returns 6, reflecting the number of products marked with an asterisk for clearance. This demonstrates the power of the tilde to transform an imprecise wildcard search into literal, precise character matching.

Related

The Ultimate Glossary of Microsoft Excel Symbols

You don’t really understand Excel until you know its symbols.

Use the tilde in criteria-based functions

Beyond COUNTIF, the tilde is essential when using a criteria-based function to search for asterisks and question marks.

Using the same inventory data as before, assume that items marked with a question mark require special accounting.

An Excel database of products, with various sections followed by a question mark.

=SUMIF(A:A,"*~?",C:C)

More specifically, you want to add up the sales values ​​of all of these items. Since the question mark is interpreted as a wildcard character by default, you must use the escape tilde right before it in your SUMIF formula:

Here, the asterisk is used as a wildcard because it is not preceded by a tilde. This means that it matches any sequence of characters at the beginning of the item code. However, the tilde-question mark sequence is interpreted as a literal question mark.

Therefore, the criteria set tells Excel to sum the values ​​in column C for any item code in column A that ends with the literal question mark.

The SUMIF function with the asterisk wildcard followed by an escaped question mark to sum the sales of all products containing a question mark.

Find and replace asterisks and question marks

Excel’s Find and Replace tool (Ctrl+H) also recognizes wildcards. Just like in formulas, if you want to target a literal asterisk or question mark, you must use the tilde to escape the wildcard function.

Imagine that you have completed the special accounting in the example above and now want to remove the question marks.

Because question marks represent only part of strings rather than the entire cell contents, make sure that

Match entire cell contents in Excel’s Find and Replace dialog box is empty. Typing ? Or *?

in the Find field and leaving the Replace with blank field replaces all contents of all cells with spaces (in other words, you will get complete data loss).

The only safe way to target just the literal question mark is to use the tilde (~?), and leaving the Replace with Blank criteria tells Excel to replace that combination with spaces, which is equivalent to a delete.

Microsoft Excel’s Find and Replace dialog box, with a tilde and marked question typed in the Find field and the Replace with field left blank.

Therefore, when you click

Question marks are removed from product names using the tilde escape used in Excel's Find and Replace dialog box.

Related

The Best Search Functions in Excel: Examples, Pros and Cons

Choose the best way to find matching values.

Filtering data with asterisks and question marks

When you use Excel’s built-in filtering tools, searches also recognize asterisks and question marks as wildcards. Using the tilde is the only way to isolate data containing literal characters.

Let’s say you want to filter all items in your inventory so that you only see items with an asterisk.

Select any cell in the dataset and click “Filter” in the data bar to add filter buttons. You can also format the range as an Excel table to automatically add filter buttons. If you type * in the filter search field, or click Text Filters > Contains and enter* Excel will return all

elements, including those without an asterisk, because the asterisk is considered a wildcard character representing any sequence of characters.

An asterisk is entered into the filter search bar in Excel and all items (including those without an asterisk) are returned.

So, to tell Excel to search for just the literal asterisk, type the escape character directly into the filter criteria.

A tilde and an asterisk are entered into the filter search bar in Excel and all items containing an asterisk are returned.

This successfully isolates elements containing an asterisk.

Escaping the escape character: finding the tilde itself

So the asterisk and question marks are the wildcards, and the tilde is the escape character. But what to do when the literal character you need to find or count is the tilde itself? The principle remains exactly the same: you must escape the character’s special function by typing two tildes.

  • This sequence works identically on all three features I covered: Formulas:
  • To count cells containing the literal tilde, use =COUNTIF(A:A,”*~~*”). Find and replace: In the Search field, enter ~~
  • to find every literal tilde in your data. Filtration: In the search, type~~ or click Text Filters > Contains and enter ~~

to isolate records containing the tilde.

The tilde isn’t the only sign you need to understand to truly understand the inner workings of Excel. For example, the at sign (@) returns a single row value instead of scattering an array, the pound sign (#) allows formulas to adjust to changes in distributed range sizes, and the double-unary operator (–) converts Boolean values ​​to numeric values.

Operating system

Windows, macOS, iPhone, iPad, Android

Free trial

1 month


Microsoft 365 includes access to Office apps like Word, Excel, and PowerPoint on up to five devices, 1TB of OneDrive storage, and more.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Check Also
Close
Back to top button