VBA - Color Cells and Font Meeting Criteria

SheelooC's picture

Sub colorCells()
' This macro colors the cell background and changes the font color
' for those cells in Column A which have negative values in Column B

Dim lastRow As Long
Dim colToColor As String
Dim colToTest As String
Dim i As Long
colToColor = "A"
colToTest = "B"
lastRow = Cells(Rows.Count, colToColor).End(xlUp).Row()
For i = 2 To lastRow
If Cells(i, colToTest) < 0 Then
Cells(i, colToColor).Select
With Selection.Interior
.Color = 10040319
End With
With Selection.Font
.Color = -16776961
End With
End If
Next i
End Sub