Set the value in a range by cell index : Range Loop « Excel « VBA / Excel / Access / Word






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

 








Related examples in the same category

1.For Each Loops for a range
2.Loop through a range cell by cell
3.Loop through all cells in a range
4.Get Rows from a range
5.Get rows from a named range (name the range before running this cript)