User-Defined Functions

css navigation by Css3Menu.com

Count Numeric Values Function

After producing a macro/module, I decided that a function would be more useful.
Public X As Long, Y As Long, D As Long, G As Variant
'User-defined function to count numeric values in a string  =CountNumbers()

Function CountNumbers(theString)
    D = 0
    For X = 1 To Len(theString)   'build outside loop
        G = Mid(Cells(4, 1), X, 1)  'Get character to compare
            For Y = 0 To 9 Step 1   'Get numbers to count
                If Y = G Then       'Compare string
                    D = D + 1       'Count
                End If              'End
        Next
    Next
    CountNumbers = D         'Write answer
End Function

Use the function as =CountNumbers(theString.address)

© 2003-2024

Updated:  06/21/2024 07:42
This page added:  03 June 2003