Characters Object

The Characters object allows you to modify individual characters in a text string. Use Characters (start, length), where start is the start character number and length is the number of characters, to return a Characters object. The following procedure changes the font color of the first letter of every word found in the UsedRange. The result of this procedure is shown below.

Student fsiame_Scores

Ann Mat luck 133

Tonya Walsh 149

Sub Format1stLetters()

Dim myChr As Characters Dim i As Integer

For Each cell In Sheets(1).UsedRange If Not IsNumeric(cell) Then

Set myChr = cell.Characters(1, 1) myChr.Font.Color = RGB(128, 0, 255) For i = 1 To Len(cell.Text) If Asc(Mid(cell, i, 1)) = 32 Then Set myChr = cell.Characters(i + 1, 1) myChr.Font.Color = RGB(255, 0, 0) End If Next End If

Next End Sub

0 0

Post a comment