Showing posts with label Characters property of Range Object. Show all posts
Showing posts with label Characters property of Range Object. Show all posts

Thursday, July 28, 2011

Use of Range.Characters

If you want to highlight Character which meet with your Criteria , You can use the Below Code :



Sub HighLight()

Application.ScreenUpdating = False
On Error Resume Next
    Dim cell As Range
    Dim rng As Range
    Dim st As String
    Dim loc As Integer
Dim n as string
    st = ""
        Set rng = ActiveSheet.UsedRange
            For Each cell In rng
                If cell.Value <> "" Then
                    st = st & cell.Value
                End If
            Next
           
                For i = 1 To Len(st)
                    n = Mid(st, i, 1) & Mid(st, i + 1, 1) & Mid(st, i + 2, 1)
                    If Asc(Mid(n, 1, 1)) > 64 And Asc(Mid(n, 1, 1)) < 91 And Asc(Mid(n, 2, 1)) > 64 And Asc(Mid(n, 2, 1)) < 91 And Asc(Mid(n, 3, 1)) > 64 And Asc(Mid(n, 3, 1)) < 91 Then
                    
                           
                            Cells.Find(What:=n, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
                            xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=True _
                            , SearchFormat:=False).Activate
                            loc = WorksheetFunction.Find(n, ActiveCell.Value, 1)
                    ActiveCell.Characters(loc, 3).Font.ColorIndex = 26
                    ActiveCell.Characters(loc, 3).Font.Bold = True
                    i = i + 3
                     End If
                Next
               
                Application.ScreenUpdating = True
               
End Sub