sbeatton
Active Member
- Joined
- May 19, 2004
- Messages
- 411
I am trying to write a UDF to extract sections of formulae from the below. I found the custom UDF below but not having much fun trying to understannd it. Am I going about this the right way / can someone please assist (even if setting me on the right track).
This is the UDF I am tring to utilise (copied from PGC01 http://www.mrexcel.com/forum/showthread.php?t=308297&highlight=split+formula+number)
Excel Workbook | ||||||
---|---|---|---|---|---|---|
C | D | E | F | |||
1 | Formula | Part 1 | Part 2 | Part 3 | ||
2 | $ 1,126.87 | 1126.87 | 0 | 0 | ||
3 | $ 753.26 | 751.26 | 0 | 2 | ||
4 | $ 356.45 | 356.45 | ||||
Sheet1 |
This is the UDF I am tring to utilise (copied from PGC01 http://www.mrexcel.com/forum/showthread.php?t=308297&highlight=split+formula+number)
Code:
Function Getnumber(r As Range, lIndex As Long) As Variant
Dim oMatches As Object
If r.Count > 1 Then Exit Function
With CreateObject("vbscript.regexp")
.Pattern = "\W\d+"
.Global = True
Set oMatches = .Execute(r.Formula)
End With
If oMatches.Count >= lIndex Then
Getnumber = Mid(oMatches(lIndex - 1), 2)
Else
Getnumber = ""
End If
End Function