I would like to count all special characters (!%_*?+-,) in a cell.
For example:
With this formula =LEN(D2)-LEN(SUBSTITUTE(D2;\"!\";\"\"))
i
Here is a simple version I created:
Function CountSpecialCharacters(rng As Range) As String
Dim regEx As New RegExp, matches As MatchCollection
With regEx
.Global = True
.MultiLine = True
.IgnoreCase = False
.Pattern = "[^a-zA-Z0-9]" '~~~> this counts any character not a to z or a number
End With
Set matches = regEx.Execute(rng)
CountSpecialCharacters = matches.Count
End Function
Two points:
References > Microsoft VBScript Regular Expressions 5.5
=CountSpecialCharacters(A2)