I am trying to create a macro that will compare the values of cells in two columns labeled "Requisition Number" and "PO #" to the cells in the previous row. If the cells are the same, I want the lines to be highlighted the same color. The following is my code:
Sub changeTextColor()
Dim Color As Integer
Color = 5
'Get number of rows in the specified column
RowsCount = Range("A1", Range("A1").End(xlDown)).Rows.Count
Dim colReq As Range
Dim colPO As Range
With ActiveSheet.UsedRange.Rows(1)
Set colReq = .Find(What:="Requisition Number", LookAt:=xlWhole, MatchCase:=False, SearchFormat:=False)
Set colPO = .Find(What:="PO #", LookAt:=xlWhole, MatchCase:=False, SearchFormat:=False)
End With
'Select cell
ActiveSheet.Cells(1, colReq.Column).Select
'Loop the cells
For x = 1 To RowsCount
If (ActiveCell.Value = ActiveSheet.Cells(ActiveCell.Row + 1, ActiveCell.Column).Value) And _
ActiveSheet.Cells(ActiveCell.Row, colPO.Column).Value = ActiveSheet.Cells(ActiveCell.Row+1, colPO.Column).Value Then
ActiveCell.EntireRow.Font.ColorIndex = Color
ActiveCell.EntireRow+1.Font.ColorIndex = Color
Else
Color = Color + 5
End If
ActiveCell.Offset(1, 0).Select
Next
End Sub
I am receiving the error "Subscript out of range" in the following lines of my code, and am not sure how to fix it?
ActiveCell.EntireRow.Font.ColorIndex = Color
ActiveCell.EntireRow+1.Font.ColorIndex = Color