Home |
Search |
Today's Posts |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Fri, 13 Jul 2012 16:34:38 -0400, Ron Rosenfeld wrote:
On Fri, 13 Jul 2012 13:15:07 -0700, "joeu2004" wrote: which assumes that you do not have "." in text. Excellent point! And one which I failed to consider in my regex solution. Fortunately, only requires a change in the regex to take that into account. And while I'm sure there are more efficient regexes for this purpose, this seems to work: ================================== Option Explicit Function NumDecDispl(rg As Range) As Variant Dim v() As Variant, c As Range Dim re As Object Const sPat As String = "^.*?\S*\.(\d+).*$" Dim i As Long Set re = CreateObject("vbscript.regexp") With re .Global = False .Pattern = sPat .MultiLine = True End With If rg.Count = 1 Then NumDecDispl = Len(re.Replace(rg.Text, "$1")) Else ReDim v(0 To rg.Count - 1) For Each c In rg v(i) = Len(re.Replace(c.Text, "$1")) i = i + 1 Next c NumDecDispl = v End If End Function ===================================== The regex should be changed to: ^.*?\d\.(\d+).*$ and .Global = True |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
how to check if a number has no more than 2 decimal digits | Excel Programming | |||
Digits to the right of decimal point | Excel Discussion (Misc queries) | |||
Number format still uses decimal point | New Users to Excel | |||
Converting 2-place decimal value to floating point decimal number with leading zero | Excel Discussion (Misc queries) | |||
Displaying only digits after the decimal point | Excel Worksheet Functions |