This post will guide you how to remove non numeric characters from cells with a formula in Excel. How do I remove non-numeric characters in cells in Excel. How to remove non-numeric characters from cells with VBA Code in Excel. Or how to strip out non-numeric characters from a given cell in Excel.
Removing Non Numeric Characters with a Formula
Assuming that you have a list of data in range B1:B5, and you want to remove all non-numeric characters from the range of cells B1:B5. How to achieve it. You can use an Excel Array formula based on the TEXTJOIN function, the IFERROR function, the ROW function and the INDIRECT function. Like this:
You need to Type this formula into a blank cell and then press CTRL +Shift + Enter keys to change the formula as an Array formula. and then drag the AutoFill Handle from C1 to C5.
Removing Non Numeric Characters with User Defined Function
You can also try to write an user defined function with VBA code to remove all non numeric characters from a cell in Excel. Just do the following steps:
#1 open your excel workbook and then click on “Visual Basic” command under DEVELOPER Tab, or just press “ALT+F11” shortcut.
#2 then the “Visual Basic Editor” window will appear.
#3 click “Insert” ->”Module” to create a new module.
#4 paste the below VBA code into the code window. Then clicking “Save” button.
Function RemoveAllNonNums(myCell As String) Dim myChar As String Dim x As Integer Dim i As String i = "" For x = 1 To Len(myCell) myChar = Mid(myCell, x, 1) If Asc(myChar) >= 48 And _ Asc(myChar) <= 57 Then i = i & myChar End If Next RemoveAllNonNums = Val(i)
#5 back to the current worksheet, try to enter the below formula in Cell C1.
You can also use the following VBA macro to achieve the same result.
Sub RemoveAllNonNums() Dim myR As Range Dim myRange As Range Set myRange = Application.Selection Set myRange = Application.InputBox("select one range that you want to remove non-numeric characters", RemoveAllNonNums, myRange.Address, Type:=8) For Each myR In myRange myOut = "" For i = 1 To Len(myR.Value) tmp = Mid(myR.Value, i, 1) If tmp Like "[0-9]" Then myStr = tmp Else myStr = "" End If myOut = myOut & myStr Next i myR.Value = myOut Next End Sub
Removing Numeric characters only
If you only want to remove all numeric characters from a cell in Excel, and you can try to use the following array formula based on the TEXTJOIN function, the IF function, the ISERR function, the MID function, the ROW function and the INDIRECt function.
Type this formula in a blank cell and then press Ctrl + Shift + Enter shortcuts in your keyboard, and then drag the AutoFill Handle over other cells to apply this array formula.
Excel ROW function
The Excel ROW function returns the row number of a cell reference.The ROW function is a build-in function in Microsoft Excel and it is categorized as a Lookup and Reference Function.The syntax of the ROW function is as below:= ROW ([reference])….
Excel IF function
The Excel IF function perform a logical test to return one value if the condition is TRUE and return another value if the condition is FALSE. The IF function is a build-in function in Microsoft Excel and it is categorized as a Logical Function.The syntax of the IF function is as below:= IF (condition, [true_value], [false_value])….
Excel MID function
The Excel MID function returns a substring from a text string at the position that you specify.The syntax of the MID function is as below:= MID (text, start_num, num_chars)…
Excel INDIRECT function
The Excel INDIRECT function returns the cell reference based on a text string, such as: type the text string “A2” in B1 cell, it just a text string, so you can use INDIRECT function to convert text string as cell reference….