Returns the number of times a substring occurs in a cell.


* For instructions on how to add a function to a workbook refer to the page under Inserting Functions
* Formula Count cells that begin with
* Formula Count cells that end with
* Formula Count cells that contain 1 text string
* Formula Count cells that contain 2 text strings
* Formula Count cells that do not contain a text string
link formulas - count-substring-occurrences
link formulas - count specific words
'* '=(LEN(text)-LEN(SUBSTITUTE(text,substring,"")))/LEN(subtring)
* The equivalent JavaScript function is COUNTSUBSTRING

Public Function COUNTSUBSTRING( _ 
            ByVal sText As String, _
            ByVal sSubString As String, _
            Optional ByVal bCaseSensitive As Boolean = True) As Integer

Dim itotalcells As Integer
   If (bCaseSensitive = True) Then
      itotalcells = UBound(VBA.Split(UCase(sText), UCase(sSubString)))
   End If
   If (bCaseSensitive = False) Then
      itotalcells = UBound(VBA.Split(sText, sSubString))
   End If
   COUNTSUBSTRING = itotalcells
End Function


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