View Single Post
  #12   Report Post  
Posted to microsoft.public.excel.programming
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default Isolate Numerical Data in Cell

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

Rick


Nice one liners, although the School formula returns the "»"

» Atlantic City H.S.


--ron