Returns the number of cells that contain text.
For instructions on how to add a function to a workbook refer to the page under Inserting Functions

'rgeValues - The range of values

Public Function COUNTTEXT(ByVal regValues As Range) As Integer
   COUNTTEXT = Application.WorksheetFunction.CountIf(rgeValues,"*")
End Function

Public Function COUNTTEXT( _
         ByVal ref_value As Range, _
         ByVal ref_string As String) As Long
Dim i As Integer
Dim count As Integer

    count = 0
    If Len(ref_string) <> 1 Then
        COUNTTEXT = CVErr(xlErrValue)
        Exit Function
    End If
    For i = 1 To Len(ref_value.Value)
        If (VBA.Mid(ref_value, i, 1) = ref_string) Then
            count = count + 1
        End If
    COUNTTEXT = count

End Function

This is equivalent to using the COUNTIF function directly.

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext