This post will describe two quick ways to remove all space characters between numbers or words in excel. How to remove unwanted spaces from cells in a select range of cells in Excel.
Assuming that you have a list of data with text string and numbers in one cell, and you want to remove all spaces between text character and numbers in those cells. You can use Excel Find & replace or SUBSTITUTE function. This post will guide you how to use those two ways to remove all spaces.
Table of Contents
1. Remove all spaces using Find and Replace option
The below steps will teach you how to remove all spaces between characters and numbers using the standard Excel Find & Replace option:
Step 1# select the range of cells that you want to remove spaces
Step 2# go to “Home” Tab, then click “Find & Select” -> “Replace…”, then the Find and Replace dialog box will appear. Or press “CTRL+H” shortcut to open the “Find and Replace” dialog box.
Step 3# press the space bar in the Find what text box, and do not input any character in the “replace with” box. Then click Replace All button. Click “OK’ button.
You will see that how many spaces have been removed from the above screenshot.
Step 4# let’s see the last result:
2. Remove all spaces using SUBSTITUTE function
You may want to remove all space characters between numbers or characters using an excel formula, then you can use the SUBSTITUTE function to create a formula as follows:
=SUBSTITUTE(A1," ", "")
You just need to enter the above formula in another cell, such as: B1, then press Enter.
Then you can select cell B1, then drag the AutoFill Handle down the other cell that you want to apply this formula.
3. remove all spaces between numbers or words using VBA Code
For the third method, we’ll delve into the power of VBA (Visual Basic for Applications) code to programmatically remove spaces between numbers or words in Excel. This method offers advanced customization, allowing you to tailor the solution to fit your specific data cleaning requirements.”
Press ‘Alt + F11‘ to open the Visual Basic for Applications editor.
Right-click on the project in the editor, select ‘Insert,’ and choose ‘Module‘ to add a new module.
Copy and paste the following VBA code into the module:
Sub RemoveSpacesWithPrompt()
Dim sourceRange As Range
Dim destinationCell As Range
Dim resultCell As Range
' Prompt user to select source range
On Error Resume Next
Set sourceRange = Application.InputBox("Select the source range with spaces", Type:=8)
On Error GoTo 0
' Exit if the user cancels the selection
If sourceRange Is Nothing Then
Exit Sub
End If
' Prompt user to select starting destination cell
On Error Resume Next
Set destinationCell = Application.InputBox("Select the starting destination cell", Type:=8)
On Error GoTo 0
' Exit if the user cancels the selection
If destinationCell Is Nothing Then
Exit Sub
End If
' Loop through each cell in the destination range and remove spaces
For Each resultCell In destinationCell.Resize(sourceRange.Rows.Count, sourceRange.Columns.Count)
resultCell.Value = Replace(sourceRange.Cells(resultCell.Row - destinationCell.Row + 1, resultCell.Column - destinationCell.Column + 1).Value, " ", "")
Next resultCell
End Sub
Close the editor and press ‘Alt + F8’
Choose ‘RemoveSpacesWithPrompt‘ and click ‘Run.’
A dialog box will appear, prompting you to select the source range with spaces to remove. Click and drag to select the desired range, then click Ok button.
Another dialog box will appear, prompting you to select the destination cell to place the result. Click on the desired destination cell, then click Ok button.
The VBA code will remove spaces from the selected source range and place the last result in the chosen destination cell.
4. Video: remove all spaces between numbers or words
This Excel video tutorial where we’ll explore three effective methods to remove all spaces between numbers or words. We dive into the first method using the SUBSTITUTE function, the second method employing the ‘Find and Replace’ feature, and the third method utilizing VBA code.
5. Related Formulas
- remove non numeric characters from a cellIf you want to remove non numeric characters from a text cell in excel, you can use the array formula:{=TEXTJOIN(“”,TRUE,IFERROR(MID(B1,ROW(INDIRECT(“1:”&LEN(B1))),1)+0,””))}…
- Remove Numeric Characters from a Cell
If you want to remove numeric characters from alphanumeric string, you can use the following complex array formula using a combination of the TEXTJOIN function, the MID function, the Row function, and the INDIRECT function.… - Using Find and Replace Tool to replace text
The Find and Replace tool is a very useful tool to replace the text string or characters with new text or character in excel.… - Remove text before the first match of a specific character
If you want to remove all characters that before the first occurrence of the comma character, you can use a formula based on the RIGHT function, the LEN function and the FIND function….. - Replace all characters before the first specific character
If you want to replace characters before the first match of the comma character in a text string in Cell B1.you still need to use the SUBSTITUTE function to replace the old_text with new_text… - Remove text after a specific character
If you want to remove all characters after the first match of the comma character in a text string in Cell B1, you can create an excel formula based on the LEFT function and FIND function….. - How to remove unwanted characters from text string
If you want to remove unwanted or specified characters from a text string, you can create an excel formula based on the SUBSTITUTE function and CHAR function…..
6. Related Functions
- Excel Substitute function
The Excel SUBSTITUTE function replaces a new text string for an old text string in a text string.The syntax of the SUBSTITUTE function is as below:= SUBSTITUTE (text, old_text, new_text,[instance_num])….
Leave a Reply
You must be logged in to post a comment.