Skip to main content

How to remove non numeric characters from cells in Excel?

Supposing you have a worksheet with lots of such data ABCD4578124YUIOH, and you only want to remove the non-numeric characters  ABCDYUIOH but keep the numeric characters in cells. Of course, you can remove those characters one by one, but right here you can get rid of the non-numeric characters from cells quickly as follows:

Remove non-numeric characters with VBA code

A handy tool to remove non-numeric characters with one click


Remove non-numeric characters with VBA code

To remove non-numeric characters from a range with VBA code, please do as follow:

1. Click Developer > Visual Basic to open the Microsoft Visual Basic for applications window. In the Microsoft Visual Basic for applications window, click Insert > Module, and then copy and paste the following codes into the module:

VBA: Remove all non-numeric characters

Sub RemoveNotNum()
'Updateby Extendoffice
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
For Each Rng In WorkRng
    xOut = ""
    For i = 1 To Len(Rng.Value)
        xTemp = Mid(Rng.Value, i, 1)
        If xTemp Like "[0-9]" Then
            xStr = xTemp
        Else
            xStr = ""
        End If
        xOut = xOut & xStr
    Next i
    Rng.Value = xOut
Next
End Sub

2. Then click the button to run the code, In the popping up KutoolsforExcel dialog box, select a range with the non-numeric characters you want to remove, and then click the OK button. See screenshot:

doc remove non numeric characters 1 copy

3. Then all non-numeric characters in selected range are removed.

doc remove non numeric characters 2

If the numbers with decimal points, you can use the following VBA:

Sub RemoveNotNum()
'Updateby Extendoffice
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
For Each Rng In WorkRng
    xOut = ""
    For i = 1 To Len(Rng.Value)
        xTemp = Mid(Rng.Value, i, 1)
        If xTemp Like "[0-9.]" Then
            xStr = xTemp
        Else
            xStr = ""
        End If
        xOut = xOut & xStr
    Next i
    Rng.Value = xOut
Next
End Sub

You can see the results as below screenshot shown:

doc remove non numeric characters 3


A handy tool to remove non-numeric characters with one click

For removing non-numeric characters in a range, Kutools for Excel’s Remove Characters utility can get it done with one click.

Kutools for Excel : with more than 300 handy Excel add-ins, free to try with no limitation in 30 days. 

After installing Kutools for Excel, please do as below:

1. Highlight the range you want to remove non-numeric characters. Click Kutools > Text > Remove Characters.

doc remove non numeric characters 4

2. In the Remove Characters dialog box, check the Non-numeric option in the Remove Characters section, and then click the OK or Apply button. And the non-numeric characters are removed from the selection immediately. See screenshot:

doc remove non numeric characters 5

Click to Download Kutools for Excel and free trial Now!

For more detailed information about Remove Characters of Kutools for Excel, please visit Remove characters features description.


Demo: Remove numeric, alphabetic, non-printable or alphanumeric characters from cells

Kutools for Excel: with more than 300 handy Excel add-ins, free to try with no limitation in 30 days. Download and free trial Now!

Related articles:

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...

Description


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
Comments (13)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
HI Thanks for the coding, i am getting the syntax error highlighted on For i = 1 To Len(Rng.Value) and the debug Sub RemoveNotNum() is highlighted in yellow.. kindly advice.
This comment was minimized by the moderator on the site
The VBA works great. I modified it to always work on a column, as shown:

For Each Cell In Range("B2:B" & ActiveSheet.UsedRange.Rows.Count)

xOut = ""

For i = 1 To Len(Cell.Value)

xTemp = Mid(Cell.Value, i, 1)

If xTemp Like "[0-9]" Then

xStr = xTemp

Else

xStr = ""

End If

xOut = xOut & xStr

Next i

Cell.Value = xOut

Next

I also used this to sort a column by the last digit, changing the last part to Cell.Value = Right(xOut, 1) then sorting it numerically.
This comment was minimized by the moderator on the site
Send me it on my email id
This comment was minimized by the moderator on the site
Hi, I want to use this macro but want to pre-define a range. Can you please let me know how to pre-define the range. Thanks, Samit
This comment was minimized by the moderator on the site
Just wanted to let you know that if the string starts with zero(s), or starts with letters, followed by zero(s), followed by the rest of the string this will remove all of the beginning zeroes. This is weird because it doesn't remove the zero(s) if they are between other non-zero numbers within the string, only if they start the string or are the first numbers after the initial letters in a string. Example. 0060100 would come out as 60100 PFF057726 would come out as 57726. Let me know if you have an explanation for this and can think of a solution. Thank you.
This comment was minimized by the moderator on the site
Thanx Guys for such a nice work. The script is awesome and it worked for. Keep it up guys.
This comment was minimized by the moderator on the site
Use this Formaula for replacing the existing character with the new one =SUBSTITUTE(text,old_text,new_text,[instance_num]) for ex-=SUBSTITUTE(TRIM(G1),"/","") Wish U all Happy Easter 2015
This comment was minimized by the moderator on the site
I received an error when I hit the > run button in the developer: Compile Error: Expected:end of statement and the word "non" in non-numeric is highlighted
This comment was minimized by the moderator on the site
Wow. that worked , exactly what I needed. Thanks,
This comment was minimized by the moderator on the site
Awesome Worked GREAT!!!!!!!!
This comment was minimized by the moderator on the site
wouldn't be better to replace the input-box method by just setting WorkRng like this: Set WorkRng = Intersect(ActiveSheet.UsedRange, Selection) that way if user select a entire column it wouldn't generate any error.
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations