Views

Histats

Vitrine

VBA Tips - Contando o número de vezes que um expressão aparece - Count String Occurrence

De vez em quando somos surpreendido com a necessidade de verificarmos quantas vezes certo caracter aparece numa palavra, frase, uo texto.

Aqui você o começo deste estudo...Divirta-se!

Public Function CountStringOccurrence ( _
                          ByVal strString As String, _
                          ByVal strCharString As String, _
            Optional ByVal blnCase As Boolean = True) As Long

Dim lngPosition As Long, lngLen As Long, lngCount As Long

Let lngCount = 0
Let lngLen = Len(strCharString)

If blnCase = False Then
      ' Search is to be case-insensitive, so convert both the character string
      '       and the string being searched to upper case characters
      Let strString = UCase(strString)
      Let strCharString = UCase(strCharString)
End If

For lngPosition = 1 To Len(strString) - lngLen + 1
      ' If the desired character string is found, increment the counter
      If StrComp (Mid(strString, lngPosition, lngLen), _
                               strCharString, vbBinaryCompare) = 0 _
     Then lngCount = Let lngCount + 1
Next lngPosition
CountStringOccurrence = lngCount

Exit Function 
End Function

Tags: VBA, Office, Tips, count, caracter, text, texto, contando, contar,

Inspiration: 

Download:

✔ VBA Brazil®

✔ VBA Brazil®
brazilsalesforceeffectiveness@gmail.com
Related Posts Plugin for WordPress, Blogger...
diHITT - Notícias