View Single Post
  #14   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\) Rick Rothstein \(MVP - VB\) is offline
external usenet poster
 
Posts: 2,202
Default Isolate Numerical Data in Cell


"Ron Rosenfeld" wrote in message
...
On Sun, 26 Aug 2007 20:41:07 -0400, "Rick Rothstein \(MVP - VB\)"
wrote:

Function SchoolNums(str As String, Index As Long)
Dim re As Object
Dim mc As Object
Set re = CreateObject("vbscript.regexp")
re.Global = True
re.Pattern = "\((\d+)-(\d+)-(\d+)"
If re.test(str) = True Then
Set mc = re.Execute(str)
SchoolNums = mc(0).submatches(Index - 1)
End If
End Function


And the final one-liner....

Function SchoolNums(str As String, Index As Long)
SchoolNums = Split(Mid(Replace(str, ")", "-"), _
InStr(str, "(") + 1), "-")(Index - 1)
End Function


Nice one liners,


Thanks! It is kind of what I am "famous" for back in the compiled VB
newsgroups.

although the School formula returns the "»"


Not if the string doesn't have the quote marks around it. But fair enough...
it could. I just posted this correction back in the School function
subthread...

Function School(str As String) As String
School = Trim(Split(Split(str, "(")(0), "»")(1))
End Function

Rick