Extracting Numbers From A String

k9nny

Board Regular
Joined
Feb 15, 2005
Messages
93
Hello everyone,

I would like to be able to extract the quantity from this string. In this case it is 100.00, but the quantity is rarely in exactly the same position, but it is always followed by ‘EA’ and ‘0%’. Is it possible to extract a number based on the characters that follow?

10 60092025 0303110106 ELBOW 25MM X 90 DEG 100.00 EA 0% £0.48 £48.00

Thanks, Kenny.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
In your example 100.00 is NOT between "EA" and "0%".
 
Upvote 0
UDF
Set reference: Tools -> References -> Microsoft VBScript Regular Expressions 5.5

Code:
Function Quantity(Str As String) As String

    ' Set reference: Tools -> References -> Microsoft VBScript Regular Expressions 5.5
    
    Dim re As New RegExp
    Dim s As String
    
    With re
        .Global = False
        .IgnoreCase = True
        .Pattern = "DEG\s+(.+)\s+EA"
    End With
    
    Quantity = re.Execute(Str)(0).SubMatches(0)

End Function
 
Upvote 0
THANK Mr. Mike Grirvin, what ever little i know in excel is learned from Mike's "EXCELISFUN" Youtube channel
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,711
Members
452,939
Latest member
WCrawford

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