ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Retreiving only numeric values from a string (https://www.excelbanter.com/excel-programming/410276-retreiving-only-numeric-values-string.html)

ALEX

Retreiving only numeric values from a string
 
There are two parts I am trying to accomplish for a set of data I have in
column A.

What I have Results I would like
A1:kkdd55dd B1:55
A2:eaa5788ee B2:5788
A3:sfse B3:455
A4:
A5:
A6:455dae

If possible I wanted to have a function where it would Search at a range
from A1:A10 and place the first set of numbers it found (always be together)
in B1, the second set of numbers it finds placed in B2 and so on. As a
reminder I cannot download any type of files if that is to be suggested.

-thank you

Norman Jones[_2_]

Retreiving only numeric values from a string
 
Hi Alex,

Try posting the following user defined
function into a standard module:

'=============
Public Function NumberOnly( _
sStr As String) As Variant
Dim oRegExp As Object

Application.Volatile
Set oRegExp = CreateObject("VBScript.RegExp")

With oRegExp
.IgnoreCase = True
.Global = True
oRegExp.Pattern = "/d"
NumberOnly = .Replace(sStr, vbNullString)
If IsNumeric(NumberOnly) Then _
NumberOnly = CDbl(NumberOnly)
End With
End Function
'<<=============

With the data of interest in A1:A10.
enter:

=NumberOnly(A1)

in B1 and drag the formula down to B10.



---
Regards.
Norman


"Alex" wrote in message
...
There are two parts I am trying to accomplish for a set of data I have in
column A.

What I have Results I would like
A1:kkdd55dd B1:55
A2:eaa5788ee B2:5788
A3:sfse B3:455
A4:
A5:
A6:455dae

If possible I wanted to have a function where it would Search at a range
from A1:A10 and place the first set of numbers it found (always be
together)
in B1, the second set of numbers it finds placed in B2 and so on. As a
reminder I cannot download any type of files if that is to be suggested.

-thank you



Mike H

Retreiving only numeric values from a string
 
Try this non VBA attempt

=--MID(A1,MIN(FIND({0,1,2,3,4,5,6,7,8,9},A1&"01234567 89")),SUMPRODUCT(--ISNUMBER(--MID(A1,ROW($1:$1000),1))))

Mike

"Alex" wrote:

There are two parts I am trying to accomplish for a set of data I have in
column A.

What I have Results I would like
A1:kkdd55dd B1:55
A2:eaa5788ee B2:5788
A3:sfse B3:455
A4:
A5:
A6:455dae

If possible I wanted to have a function where it would Search at a range
from A1:A10 and place the first set of numbers it found (always be together)
in B1, the second set of numbers it finds placed in B2 and so on. As a
reminder I cannot download any type of files if that is to be suggested.

-thank you


Norman Jones[_2_]

Retreiving only numeric values from a string
 
Hi Alex.

As Mike has introduced the possibility
of a non VBA approach, see:


Extracting numbers from alphanumeric strings
http://office.microsoft.com/en-us/ex...549011033.aspx


---
Regards.
Norman


"Alex" wrote in message
...
There are two parts I am trying to accomplish for a set of data I have in
column A.

What I have Results I would like
A1:kkdd55dd B1:55
A2:eaa5788ee B2:5788
A3:sfse B3:455
A4:
A5:
A6:455dae

If possible I wanted to have a function where it would Search at a range
from A1:A10 and place the first set of numbers it found (always be
together)
in B1, the second set of numbers it finds placed in B2 and so on. As a
reminder I cannot download any type of files if that is to be suggested.

-thank you



Norman Jones[_2_]

Retreiving only numeric values from a string
 
Hi Alex,

oRegExp.Pattern = "/d"


Should read:

oRegExp.Pattern = "\D+"

and:

Application.Volatile


is unnecessary.

Therefore, replace the suggested function with:

'=============
Public Function NumberOnly( _
sStr As String) As Variant
Dim oRegExp As Object

Set oRegExp = CreateObject("VBScript.RegExp")

With oRegExp
.IgnoreCase = True
.Global = True
oRegExp.Pattern = "\D+"
NumberOnly = .Replace(sStr, vbNullString)
If IsNumeric(NumberOnly) Then _
NumberOnly = CDbl(NumberOnly)
End With
End Function
'<<=============



---
Regards.
Norman

ALEX

Retreiving only numeric values from a string
 
Thank you Norman and Mike, both methods worked great. I appreciate both
responses.

"Norman Jones" wrote:

Hi Alex.

As Mike has introduced the possibility
of a non VBA approach, see:


Extracting numbers from alphanumeric strings
http://office.microsoft.com/en-us/ex...549011033.aspx


---
Regards.
Norman


"Alex" wrote in message
...
There are two parts I am trying to accomplish for a set of data I have in
column A.

What I have Results I would like
A1:kkdd55dd B1:55
A2:eaa5788ee B2:5788
A3:sfse B3:455
A4:
A5:
A6:455dae

If possible I wanted to have a function where it would Search at a range
from A1:A10 and place the first set of numbers it found (always be
together)
in B1, the second set of numbers it finds placed in B2 and so on. As a
reminder I cannot download any type of files if that is to be suggested.

-thank you




All times are GMT +1. The time now is 09:55 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com