If you need to remove one special character (for example an unconventional space): count at which position the character is in the string. Then you can extract it with the MID function. After you have only this character, you use the CODE function to get it’s code. The TRIM function removes extra space characters and starting and ending space characters in the text of the cell. In Excel, you can also use a macro to count the occurrences of a specific character in a cell, or range of cells. In order to enable typing the special characters, Microsoft uses alt keys on the keyboard as a modifier. You can use the alt key and the decimal value of the Unicode character to insert symbols on your PC. Things are different on macOS. Apple keyboard has option keys (also called alt keys) which you can use to insert symbols. Or the opposite – we look to find the Excel character codes for certain characters. In such cases we must usually revert to using the CHAR Excel function or the CODE Excel function. Let us explore these functions and how to use them both in Excel and VBA today. Excel Character Codes. First let us start with exploring the Excel Character codes.
- Excel Replace All Special Characters
- Excel Special Characters List
- Search Special Characters In Excel
- Excel Find Character Code
- Excel For Mac Find Special Characters Using
- Excel Special Character Code List
In this article, we will learn how to remove unwanted characters in Excel.
Sometimes you get uncleaned data set in excel & I don’t want you being banging your head on wall to clean the data set.
In simple words, Excel lets you clean unwanted characters using SUBSTITUTE function .
Syntax to clean unwanted characters
Syntax to clean unwanted characters
“” : empty string
Let’s use this function on some of the uncleaned values shown below.
Let's understand this one by one:
1st case:
When you need to remove just the spaces from the data set. Use the single space as remove_char in the formula
Let's understand this one by one:
1st case:
When you need to remove just the spaces from the data set. Use the single space as remove_char in the formula
Formula
=SUBSTITUTE(A2,' ',')
Explanation:
This formula extracts every single space in the cell value and replaces it with an empty string.
As you can see the first value is cleaned.
This formula extracts every single space in the cell value and replaces it with an empty string.
As you can see the first value is cleaned.
Second Case:
When you know a specific character to remove from the cell value, just use that character as remove_char in the formula
Use the formula
When you know a specific character to remove from the cell value, just use that character as remove_char in the formula
Use the formula
As you can see the value is cleaned.
Third Case:
When you wish to remove the character by using its code. This can help you in removing case sensitive character.
Just use the char(code) in place of remove_char. To know the code of the character uses the function shown below.
Use the formula to remove the character
When you wish to remove the character by using its code. This can help you in removing case sensitive character.
Just use the char(code) in place of remove_char. To know the code of the character uses the function shown below.
Use the formula to remove the character
=SUBSTITUTE(A4,CHAR(38),')
As you can see the value is cleaned.
Final Case:
When you wish to remove the character which comes at the first position in the text. You need to grab the code of the character using the LEFT & CODE function.
Use the formula
When you wish to remove the character which comes at the first position in the text. You need to grab the code of the character using the LEFT & CODE function.
Use the formula
Explanation:
LEFT(A5) grabs the single space code in the formula using LEFT & CODE function and giving as input to char function to replace it with an empty string.
LEFT(A5) grabs the single space code in the formula using LEFT & CODE function and giving as input to char function to replace it with an empty string.
Excel Replace All Special Characters
As you can see the value is cleaned in both the cases whether it is single space or any other character.
I hope you understood how to remove unwanted characters from the text using SUBSTITUTE function in Excel. Explore more articles on Excel TEXT function here. Please feel free to state your query or feedback for the above article.
Related Articles:
Popular Articles:
We know that TRIM and CLEAN Excel functions are used to clean up unprintable characters and extra spaces from strings but they don't help much in identifying strings containing any special character like @ or ! etc. In such cases we use UDFs.
So if you want to know if a string contains any special characters, you will not find any Excel formula or function to do so. We can find the special characters that are on the keyboard by manually typing but you can't know if there are symbols in the string or not.
Finding any special characters can be very important for data cleaning purposes. And in some cases, it must be done. So how do we do this in Excel? How can we know if a string contains any special characters? Well, we can use UDF to do so.
The below formula will return TRUE if any cell contains any characters other than 1 to 0 and A to Z (in both cases). If it does not find any special characters it will return FALSE.
Generic Formula
=ContainsSpecialCharacters(string) |
String: The string that you want to check for special characters.
For this formula to work, you will need to put the code below in the module of your workbook.
So open Excel. Press ALT+F11 to open VBE. Insert a module from the Insert menu. Copy the code below and paste it into the module.
Now the function is ready to be used.
Go to the worksheet in the workbook that contains the strings that you want to check.
Go to the worksheet in the workbook that contains the strings that you want to check.
Write the below formula in cell C2:
Excel Special Characters List
=ContainsSpecialCharacters(B13) |
It returns TRUE for the first string since it contains a special character. When you copy the formula down it shows FALSE for B14 string and so on.
But strangely it shows TRUE for the last string 'Exceltip.com'. It is because it contains a dot (.). But why so? Let's examine the code to understand.
How does the function work?
We are iterating through all the characters of the string using the For loop and mid function of VBA. The Mid function extracts one character at a time from string and stores it into ch variable.
Now the main part comes. We use the select case statement to check what the ch variable contains.
We tell VBA to check if ch contains any of the defined values. I have defined 0 to 9, A to Z, a to z and ' ' (space). If c
h contains any of these, we set it's value to False.
h contains any of these, we set it's value to False.
You can see that we don't have a dot (.) on the list and this is why we get TRUE for the string that contains dot. You can add any character to the list to be exempt from the formula.
If ch contains any character other than the listed characters, we set the function's result to True and end the loop right there.
So yeah this how it works. But if you want to clean special characters, you will need to make some changes in the function.
How to Clean Special Characters From Strings in Excel?
To clean special characters from a string in Excel, I have created another custom function in VBA. The syntax of the function is:
=CleanSpecialCharacters(string) |
This function returns a cleaned version of the string passed into it. The new string will not contain any of the special characters.
The code of this function goes like this:
Copy this in the same module you copied in the above code.
When you use this formula on the strings this is how the results will be:
You can see every special character is removed from the string including the dot.
How does it work?
It works the same as the above function. The only difference is this function replaces every special character with a null character. Forms a new string and returns this string.
If you want to exempt any character from getting cleaned, you can add it to the list in the code. Excel will pardon that special character.
So yeah guys, this is how you can find and replace special characters from a string in Excel. I hope this was explanatory enough and helpful. If it doesn't help you in solving your problem, let us know in the comments section below.
Related Articles:
How to Use TRIM function in Excel: The TRIM function is used to trim strings and clean any trailing or leading spaces from string. This helps us in the cleaning process of data a lot.
How to use the CLEAN function in Excel: Clean function is used to clean up unprintable characters from the string. This function is mostly used with the TRIM function to clean up imported foreign data.
Replace text from end of a string starting from variable position: To replace text from the end of the string, we use the REPLACE function. The REPLACE function uses the position of text in the string to replace it.
How to Check if a string contains one of many texts in Excel: To find check if a string contains any of multiple text, we use this formula. We use the SUM function to sum up all the matches and then perform a logic to check if the string contains any of the multiple strings.
Count Cells that contain specific text: A simple COUNTIF function will do the magic. To count the number of multiple cells that contain a given string we use the wildcard operator with the COUNTIF function.
Search Special Characters In Excel
Excel REPLACE vs SUBSTITUTE function: The REPLACE and SUBSTITUTE functions are the most misunderstood functions. To find and replace a given text we use the SUBSTITUTE function. Where REPLACE is used to replace a number of characters in string…
Popular Articles:
Excel Find Character Code
50 Excel Shortcuts to Increase Your Productivity | Get faster at your task. These 50 shortcuts will make you work even faster on Excel.
Excel For Mac Find Special Characters Using
How to use Excel VLOOKUP Function| This is one of the most used and popular functions of excel that is used to lookup value from different ranges and sheets.
How to use theExcel COUNTIF Function| Count values with conditions using this amazing function. You don't need to filter your data to count specific values. Countif function is essential to prepare your dashboard.
Excel Special Character Code List
How to Use SUMIF Function in Excel| This is another dashboard essential function. This helps you sum up values on specific conditions.
MagicISO can also convert any image file format including BIN to the standard ISO format. It can handle images created by CD burning software (Nero Burning ROM, Easy CD Create, and so on) or virtual DVD/CD-ROM driver software (Daemon-tools). MagicISO has the ability to create ISO image files as well. DAEMON Tools is a handy tool that has been developed to help you back up various types of physical disks, including CD/DVD/Blu-ray, and create “disk image” files and virtual drives. Once successfully finished, the software will make your OS see virtual drives like real ones. The overall process runs smoothly and only takes a couple of clicks. ISO image creator and burner Daemon Tools Lite is a free burning tool that enables you to create and burn images and add virtual DVD drives to your system. These work in the same way as physical DVDs without the need for discs. Instead, store the content on your hard disk and access it with ease. Daemon tool filehippo.