Characters Object Example

This example formats all the capital letters in the active cell in red with 16-point bold text:

Sub FormatCellCapitals()

Dim sText As String

Dim oChars As Characters

Dim i As Integer

'Get the text of the active cell

sText = ActiveCell.Text

'Loop through the text

For i = 1 To Len(sText)

'Is this character a capital letter?

If Asc(Mid(sText, i, 1)) > 64 And Asc(Mid(sText, i, 1))

< 91 Then

'Yes, so get the Characters object

Set oChars = ActiveCell.Characters(i, 1)

'Format the Characters object in Red, 16pt Bold.

With oChars

.Font.Color = RGB(255, 0, 0)

.Font.Size = 16

.Font.Bold = True

End With

End If

Next

End Sub

0 0

Post a comment