Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 160
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 160
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default 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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting Info From Within A Text String nospaminlich Excel Worksheet Functions 4 January 31st 07 10:31 PM
Extracting info from web pages \\sh Excel Discussion (Misc queries) 0 November 1st 06 05:39 PM
Extracting info to new tables Dazed & Confused Excel Discussion (Misc queries) 1 September 19th 06 09:32 AM
Extracting info from a database J David Southwick Excel Programming 3 December 29th 03 10:19 PM
extracting info the best way shiepowk Excel Programming 1 November 5th 03 11:26 AM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"