Taking out everything but the numbers

mizunobill

New Member
Joined
Feb 5, 2004
Messages
13
Is there a way to take all characters except numbers out of a string. Example:
47/21.25-16 LBT would convert to 47212516
af 4X10.5-4 // 18 would go to 4105418

Thanks for your help!
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Try the following. It will take all data in column A, and place only the numbers within into column B.

Code:
Public Sub StripAlphaNumeric()
Dim str     As String, _
    iPos    As Long, _
    i       As Long, _
    LR      As Long
    
LR = Range("A" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
For i = 1 To LR
    str = ""
    For iPos = 1 To Len(Range("A" & i).Value)
        If Mid$(Range("A" & i).Value, iPos, 1) Like "#" Then
            str = str & Mid$(Range("A" & i).Value, iPos, 1)
        End If
    Next iPos
    Range("B" & i).Value = str
Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,506
Messages
6,179,158
Members
452,892
Latest member
yadavagiri

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top