LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #14   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default pulling out Numbers

Thanks Ron,

I'm only on my 4th read of John Walkenbach's 2003 bible so perhaps some way
off this yet.

Mike

"Ron Rosenfeld" wrote:

Mike,

It uses "Regular Expressions" which is a feature included with VBA.

The CreateObject method sets up the reference to Microsoft VBScript Regular
Expressions 5.5. Instead of that method, one can also select Tools/References
(from the VBEditor top menu) and select that as a reference. This latter
method has the advantage that properties will pop up when you are writing the
macro, as they do for other objects.

The Pattern "\D" means "match every character that is not a digit (not 0..9).
The replace method then looks at "str" and replaces every match with nothing
(""), thereby removing all the non-digits.

http://support.microsoft.com/default...02&Product=vbb
http://msdn2.microsoft.com/en-us/library/1400241x.aspx



On Tue, 21 Aug 2007 11:36:00 -0700, Mike H
wrote:

Ron,

Excellent. any chance of a quick rundown on how it works or a web reference
please?

Mike H

"Ron Rosenfeld" wrote:

On Tue, 21 Aug 2007 10:28:00 -0700, peyman
wrote:

hi,
how can I pull out numbers from a string?like:
aa012985 to 012985
12ab-059 to 12059
the letters or characters might be either at the first, middle or at the end
of a string.
thanx in advance.

You can use a UDF.

To enter the UDF, <alt-F11 opens the VB Editor.

Ensure your project is highlighted in the Project Explorer window, then
Insert/Module and paste the code below into the window that opens.

To use this UDF, enter =ExtrNums(cell_ref) into some cell.

===============================
Option Explicit

Function ExtrNums(str As String)
Dim re As Object
Set re = CreateObject("VBScript.RegExp")
re.Global = True
re.Pattern = "\D"
ExtrNums = re.Replace(str, "")
End Function
================================


--ron


--ron

 
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
formula for pulling only numbers but not text from another cell Jamie Excel Worksheet Functions 7 May 17th 07 07:56 PM
function for pulling certain numbers from a cell? datasorter Excel Worksheet Functions 3 August 3rd 06 12:30 AM
Pulling the largest numbers Melanie Excel Worksheet Functions 2 May 23rd 06 07:33 PM
pulling numbers from hhh:mm:ss tri_p Excel Worksheet Functions 2 October 3rd 05 08:36 PM
Pulling larger numbers from group Smint Excel Worksheet Functions 3 June 14th 05 08:55 PM


All times are GMT +1. The time now is 07:32 AM.

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"