Consulting

Results 1 to 2 of 2

Thread: Counting letters and numbers separately in a single cell

  1. #1
    VBAX Newbie
    Joined
    Aug 2019
    Posts
    1
    Location

    Count characters in cell and then highlight

    How to count characters in cell and then highlight.
    Last edited by ss2012; 08-22-2019 at 12:31 AM.

  2. #2
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    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

    マナ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •