Hello,
I am trying to write a macro to highlight a group of cells based on the cell value in column A. The cell values in column A will look like:
1
1
1
2
2
2
3
3
3
What I need is to highlight all of the rows with a cell value of 1 in one color and highlight all of the rows with the next cell value as another color and finally to highlight all of the rows with the next cell value as the first color.
I have tried to write a Macro:
Dim startCell As Range, cell1 As Range, cell2 As Range
Dim rowNr&
Set startCell = ActiveCell
rowNr = startCell.Row: colNr = 45
For rowNr = startCell.Row To 200
If (Cells(rowNr, 1).Value) = (Cells(rowNr + 1, 1).Value) Then
Set cell1 = Cells(rowNr, 1)
ElseIf (Cells(rowNr, 1).Value) < (Cells(rowNr + 1, 1).Value) Then
Set cell2 = Cells(rowNr - 1, 45)
Range(cell1, cell2).Select
With Selection.Interior
.ColorIndex = 15
.Pattern = xlSolid
End With
End If
Next rowNr
End Sub
But can't seem to get it. Any help would be GREATLY appreciated!
Best Regards,
Excel Macro Noob
Bookmarks