PDA

View Full Version : [SOLVED:] Counting letters and numbers separately in a single cell



ss2012
08-21-2019, 11:44 PM
How to count characters in cell and then highlight.

mana
08-22-2019, 02:46 AM
Option Explicit

Sub test()
Dim r As Range
Dim s As String
Dim k As Long
Dim n As Long

Set r = ActiveCell

r.Font.Color = vbBlack
s = r.Value

For k = 1 To Len(s)
If Mid(s, k, 1) Like "[!0-9]" Then
n = n + 1
r.Characters(k, 1).Font.Color = vbRed
End If
Next

MsgBox n

End Sub



マナ