Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21243

Setting different font colors for characters in a cell based on character position

$
0
0
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.
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

Viewing all articles
Browse latest Browse all 21243

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>