get only the numbers from a cell

outlawspeeder

Board Regular
Joined
Jan 17, 2009
Messages
205
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
 

Some videos you may like

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

sandy666

Banned - Rules violations
Joined
Oct 24, 2015
Messages
7,499
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
 

Trevor G

Well-known Member
Joined
Jul 17, 2008
Messages
6,701
Office Version
  1. 2016
Platform
  1. Windows
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
 

jmacleary

Well-known Member
Joined
Oct 5, 2015
Messages
1,056
Office Version
  1. 365
  2. 2007
Platform
  1. Windows
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
 

Trevor G

Well-known Member
Joined
Jul 17, 2008
Messages
6,701
Office Version
  1. 2016
Platform
  1. Windows
Happy to help and thank you for letting us know you have a working solution. ;)
 

Watch MrExcel Video

Forum statistics

Threads
1,127,735
Messages
5,626,583
Members
416,192
Latest member
steinach

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
Top