Extract numbers from a string

legendsaga

New Member
Joined
Jun 6, 2018
Messages
1
Hi everyone

I want to extract all the numbers from a string and get them separated by columns or at least separated by comma

for example

the person left the cellphone 45213204456, job 3489334 house 9888234 mother 452103210, value to pay $25

result
[TABLE="width: 500"]
<tbody>[TR]
[TD]45213204456[/TD]
[TD]3489334[/TD]
[TD] 9888234[/TD]
[TD]452103210[/TD]
[TD]25[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

or

45213204456,3489334,9888234,452103210,25

I would be really grateful for the help
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Assuming your data is in Column A starting at Row 1, give this macro a try...
Code:
[table="width: 500"]
[tr]
	[td]Sub ExtractNumber()
  Dim R As Long, X As Long, Arr As Variant
  Arr = Range("A1", Cells(Rows.Count, "A").End(xlUp))
  For R = 1 To UBound(Arr)
    For X = 1 To Len(Arr(R, 1))
      If Mid(Arr(R, 1), X, 1) Like "[!0-9]" Then Mid(Arr(R, 1), X) = " "
    Next
    Arr(R, 1) = Replace(Application.Trim(Arr(R, 1)), " ", ", ")
  Next
  Range("B1").Resize(UBound(Arr)) = Arr
End Sub[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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