Mega Code Archive

 
Categories / VisualBasic Script / Excel
 

Set the value in a range by cell index

Sub ColorCells2()    Dim myRange As Range    Dim i As Long, j As Long       Set myRange = Range("A1:E5")    For i = 1 To myRange.Rows.Count       For j = 1 To myRange.Columns.Count          If myRange(i, j).Value < 10 Then             myRange(i, j).Font.ColorIndex = 5          Else             myRange(i, j).Font.ColorIndex = 1          End If       Next j    Next i End Sub