Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default finding numbers

Hi, does anyone know how I would pull numbers out of a string of text? For
example, the text: Prepare Culvert Pipe (30 Inch), I need a formula to
display just the "30". The text strings will vary so I cannot use MID to pull
out text at certain spots. Any thoughts?

Thanks,
John
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default finding numbers

Try the Val function.

Sub getNumb()
Range("A1") = "Prepare Culvert Pipe (30 Inch)")
myNumb = Val(Range("A1").Value)
MsgBox myNumb
End Sub



"johnrb7865" wrote:

Hi, does anyone know how I would pull numbers out of a string of text? For
example, the text: Prepare Culvert Pipe (30 Inch), I need a formula to
display just the "30". The text strings will vary so I cannot use MID to pull
out text at certain spots. Any thoughts?

Thanks,
John

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default finding numbers

Sorry, Val only works if the string begins with a number.

"johnrb7865" wrote:

Hi, does anyone know how I would pull numbers out of a string of text? For
example, the text: Prepare Culvert Pipe (30 Inch), I need a formula to
display just the "30". The text strings will vary so I cannot use MID to pull
out text at certain spots. Any thoughts?

Thanks,
John

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default finding numbers

Will the only numbers in the **always** be enclosed in parentheses? If so...

Number = Val(Mid(YourText, InStr(YourText, "(") + 1))

--
Rick (MVP - Excel)


"johnrb7865" wrote in message
...
Hi, does anyone know how I would pull numbers out of a string of text? For
example, the text: Prepare Culvert Pipe (30 Inch), I need a formula to
display just the "30". The text strings will vary so I cannot use MID to
pull
out text at certain spots. Any thoughts?

Thanks,
John


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 897
Default finding numbers

How about a UDF that loops through the cell, uses the LIKE function to
compare each cell to [0123456789] and if there's a match, builds a
string consisting of the matching characters?

I'm sure that's the hard way.

--JP


On Sep 22, 4:45*pm, JLGWhiz wrote:
Sorry, Val only works if the string begins with a number.



"johnrb7865" wrote:
Hi, does anyone know how I would pull numbers out of a string of text? For
example, the text: Prepare Culvert Pipe (30 Inch), I need a formula to
display just the "30". The text strings will vary so I cannot use MID to pull
out text at certain spots. Any thoughts?


Thanks,
John- Hide quoted text -


- Show quoted text -




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 897
Default finding numbers

Oops it already exists :-)

http://www.ozgrid.com/VBA/ExtractNum.htm


On Sep 22, 4:54*pm, JP wrote:
How about a UDF that loops through the cell, uses the LIKE function to
compare each cell to [0123456789] and if there's a match, builds a
string consisting of the matching characters?

I'm sure that's the hard way.

--JP

On Sep 22, 4:45*pm, JLGWhiz wrote:



Sorry, Val only works if the string begins with a number.


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default finding numbers

On Mon, 22 Sep 2008 13:23:01 -0700, johnrb7865
wrote:

Hi, does anyone know how I would pull numbers out of a string of text? For
example, the text: Prepare Culvert Pipe (30 Inch), I need a formula to
display just the "30". The text strings will vary so I cannot use MID to pull
out text at certain spots. Any thoughts?

Thanks,
John


If the value will be the first integer in the string, then:

==========================
Option Explicit
Function Nums(str As String) As Double
Dim re As Object, mc As Object
Set re = CreateObject("vbscript.regexp")
re.Pattern = "\d+"
If re.test(str) = True Then
Set mc = re.Execute(str)
Nums = mc(0).Value
End If
End Function
===========================

If the value is might be a decimal number or a fraction, then we would need to
change re.pattern.
--ron
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
finding case numbers em Excel Worksheet Functions 2 August 24th 09 02:31 PM
Finding Duplicate Numbers chadhable Excel Discussion (Misc queries) 1 May 16th 08 12:47 AM
Finding numbers or numbers and dashes in text [email protected] Excel Programming 6 April 2nd 07 12:10 PM
Finding Row Numbers Within the RangeName Goofy Excel Programming 4 October 19th 06 09:42 AM
finding numbers flat6 New Users to Excel 2 February 17th 05 10:17 PM


All times are GMT +1. The time now is 11:24 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"