I am trying to set three different colors for first 3, second 3 and last 3 characters of contents of all the cells in a range. The below code is changing the entire cell content to green, not only the first 3 characters.
Please guide me how to do this. I am very new to VB.
Please guide me how to do this. I am very new to VB.
Sub LoopAndChangeColor()
Dim i As Integer
Dim targetRange As Range
'Set targetRange = Range("A1:A10")
'For Each cell In targetRange
For i = 1 To 10
Cells(i, 1).Characters(1, 3).Font.Color = vbGreen
Cells(i, 1).Characters(4, 3).Font.Color = vbBlue
Cells(i, 1).Characters(7, 3).Font.Color = vbRed
Next
End Sub
Dim i As Integer
Dim targetRange As Range
'Set targetRange = Range("A1:A10")
'For Each cell In targetRange
For i = 1 To 10
Cells(i, 1).Characters(1, 3).Font.Color = vbGreen
Cells(i, 1).Characters(4, 3).Font.Color = vbBlue
Cells(i, 1).Characters(7, 3).Font.Color = vbRed
Next
End Sub