ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Extracting info from a string using VBA plz (https://www.excelbanter.com/excel-programming/348467-extracting-info-string-using-vba-plz.html)

Patrick

Extracting info from a string using VBA plz
 
Hello everyone!!

Need to create a custum function in Excel that will allow me to extra
a series of numbers from a string.

The string will have a fix format, so this should facilitate the process.
The numbers im looking for are always going to be serounded by brakets.

Ex: test(234)test2

From this example and using the brakets as guidlines, what type of code would
be able to extract the '234' number.

Thx for your hlp,
Patrick

Jim Thomlinson[_5_]

Extracting info from a string using VBA plz
 
Why VBA? This formula should do what you need. It assumes the text is in Cell
A1

=VALUE(MID(A1,FIND("(",A1)+1,FIND(")",A1)-FIND("(",A1)-1))
--
HTH...

Jim Thomlinson


"Patrick" wrote:

Hello everyone!!

Need to create a custum function in Excel that will allow me to extra
a series of numbers from a string.

The string will have a fix format, so this should facilitate the process.
The numbers im looking for are always going to be serounded by brakets.

Ex: test(234)test2

From this example and using the brakets as guidlines, what type of code would
be able to extract the '234' number.

Thx for your hlp,
Patrick


Toppers

Extracting info from a string using VBA plz
 
Patrick,
You colud use the following formula:

=MID(A2,FIND("(",A2,1)+1,FIND(")",A2,1)-FIND("(",A2,1)-1)

Assuming data starts in A2, place in required column and copy down.

OR

=findNum(b1)

Function findNum(rng)

findNum = Mid(rng, InStr(1, rng, "(") + 1, InStr(1, rng, ")") - InStr(1,
rng, "(") - 1)
End Function


"Patrick" wrote:

Hello everyone!!

Need to create a custum function in Excel that will allow me to extra
a series of numbers from a string.

The string will have a fix format, so this should facilitate the process.
The numbers im looking for are always going to be serounded by brakets.

Ex: test(234)test2

From this example and using the brakets as guidlines, what type of code would
be able to extract the '234' number.

Thx for your hlp,
Patrick


Patrick

Extracting info from a string using VBA plz
 
That will work for me to, thx alot Jim.....

"Jim Thomlinson" wrote:

Why VBA? This formula should do what you need. It assumes the text is in Cell
A1

=VALUE(MID(A1,FIND("(",A1)+1,FIND(")",A1)-FIND("(",A1)-1))
--
HTH...

Jim Thomlinson


"Patrick" wrote:

Hello everyone!!

Need to create a custum function in Excel that will allow me to extra
a series of numbers from a string.

The string will have a fix format, so this should facilitate the process.
The numbers im looking for are always going to be serounded by brakets.

Ex: test(234)test2

From this example and using the brakets as guidlines, what type of code would
be able to extract the '234' number.

Thx for your hlp,
Patrick


Jim Thomlinson[_5_]

Extracting info from a string using VBA plz
 
Patrick. The difference between Topper's formula and mine is that mine
returns a number, while Topper's returns a string. Since you did not specify
just pick the one that works for you...
--
HTH...

Jim Thomlinson


"Toppers" wrote:

Patrick,
You colud use the following formula:

=MID(A2,FIND("(",A2,1)+1,FIND(")",A2,1)-FIND("(",A2,1)-1)

Assuming data starts in A2, place in required column and copy down.

OR

=findNum(b1)

Function findNum(rng)

findNum = Mid(rng, InStr(1, rng, "(") + 1, InStr(1, rng, ")") - InStr(1,
rng, "(") - 1)
End Function


"Patrick" wrote:

Hello everyone!!

Need to create a custum function in Excel that will allow me to extra
a series of numbers from a string.

The string will have a fix format, so this should facilitate the process.
The numbers im looking for are always going to be serounded by brakets.

Ex: test(234)test2

From this example and using the brakets as guidlines, what type of code would
be able to extract the '234' number.

Thx for your hlp,
Patrick


JE McGimpsey

Extracting info from a string using VBA plz
 
No real need for code:

=--MID(LEFT(A1,FIND(")",A1)-1),FIND("(",A1)+1,255)

where the -- coerces the Text returned by MID() to an XL number.

However, if you need a UDF:

Public Function ExtractNumberInParens( _
ByVal sInput As String) As Variant
Dim sTemp As String
If sInput Like "*(*)*" Then
sTemp = Mid(Left(sInput, InStr(sInput, ")") - 1), _
InStr(sInput, "(") + 1)
If IsNumeric(sTemp) Then
ExtractNumberInParens = CDbl(sTemp)
End If
End If
If IsEmpty(ExtractNumberInParens) Then _
ExtractNumberInParens = CVErr(xlErrValue)
End Function




In article ,
"Patrick" wrote:

Hello everyone!!

Need to create a custum function in Excel that will allow me to extra
a series of numbers from a string.

The string will have a fix format, so this should facilitate the process.
The numbers im looking for are always going to be serounded by brakets.

Ex: test(234)test2

From this example and using the brakets as guidlines, what type of code would
be able to extract the '234' number.

Thx for your hlp,
Patrick



All times are GMT +1. The time now is 05:07 PM.

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