get only the numbers from a cell

outlawspeeder

Board Regular
Joined
Jan 17, 2009
Messages
225
Office Version
  1. 2019
Looking for code to pull numbers from a cell that has text with the number. I have some users that do not understand that excel cannot do math on cells with text and numbers.

Thank

Column A
abc 33
~rdt 45
& 344 fkfk
ddd 23 ss
44 dd 33

Result
33
45
344
23
4433
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
use Power Query

Column1Number
abc 3333
~rdt 4545
& 344 fkfk344
ddd 23 ss23
44 dd 334433

Rich (BB code):
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    TS = Table.AddColumn(Source, "Number", each Text.Select([Column1], {"0".."9"})),
    TypeNum = Table.TransformColumnTypes(TS,{{"Number", type number}}),
    TSC = Table.SelectColumns(TypeNum,{"Number"})
in
    TSC
 
Upvote 0
You could also try

VBA Code:
Sub DeleteText()
Dim cell As Range
Dim ran As Range
On Error Resume Next
Set ran = Range("a2:a500") 'Suggested range
For Each cell In ran
    lOut = ""
    For i = 1 To Len(cell.Value)
        xTemp = Mid(cell.Value, i, 1)
        If xTemp Like "[0-9]" Then
            lStr = xTemp
        Else
            lStr = ""
        End If
        lOut = lOut & lStr
    Next i
    cell.Value = lOut
Next
End Sub
 
Upvote 0
Hello there. There are a number of sites that have this answer, I copied this function from one:
VBA Code:
Function GetNumeric(CellRef As String)
Dim StringLength As Integer
StringLength = Len(CellRef)
For i = 1 To StringLength
If IsNumeric(Mid(CellRef, i, 1)) Then Result = Result & Mid(CellRef, i, 1)
Next i
GetNumeric = Result
End Function
 
Upvote 0
Happy to help and thank you for letting us know you have a working solution. ;)
 
Upvote 0

Forum statistics

Threads
1,213,484
Messages
6,113,923
Members
448,533
Latest member
thietbibeboiwasaco

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