Only Extract number from text string which is surrounded by spaces

bzuko22

New Member
Joined
Oct 1, 2013
Messages
3
Hi all,

I know there few posts about extracting numbers from text strings which I'm OK to do. My issue is to extract ONLY a number which is in between spaces, for example:

Source data - cell AResult - cell B
24m swimming 36 george12336
48 challenge23 yellow48
11xyz 12 run michael12
tennis nadal george123 brown 5656

<tbody>
</tbody>

Is this something simple to do, ideally i'd like to have macro tu run to produce this, since dealing with lots of data.

Many thanks
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Welcome to the Board!

Here is a User Defined Function I created in VBA. You can use this like any other function right on the spreadsheet, or called from other VBA code:
Code:
Function FindNumber(myEntry As Variant) As Double
'   Pulls out the first solitary number it finds in a sentence


    Dim Words() As String
    Dim i As Long


'   Split string into words, using space as delimiter
    Words = Split(myEntry, " ")


'   Loop through all the words, looking for numeric only entries
    For i = LBound(Words) To UBound(Words)
        If IsNumeric(Words(i)) Then
            FindNumber = Words(i)
            Exit For
        End If
    Next i


End Function
So, if you wanted to use it on the spreadsheet, and wanted to extract the value from cell A1, just use this formula:
=FindNumber(A1)
 
Upvote 0
This formula works with the sample given:

=LOOKUP(10^9,1*TRIM(MID(SUBSTITUTE(" "&A1&" "," ",REPT(" ",99)),99*ROW($1:$100),99)))

<tbody>
</tbody><colgroup><col></colgroup>
 
Upvote 0

Forum statistics

Threads
1,215,459
Messages
6,124,948
Members
449,198
Latest member
MhammadishaqKhan

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