Reputation: 196
Upvotes: 2
Views: 1278
Reputation: 30047
This macro alternates between 2 colours, changing when the value in column A changes.
Sub Highlighting()
Dim rw As Long
Dim lastrw As Long
' Define 2 different highlighting colours by their RGB values
Dim col1 As Long
Dim col2 As Long
col1 = RGB(255, 230, 180)
col2 = RGB(180, 230, 255)
' "Current" colour for highlighting
Dim col As Long
col = col1
With ThisWorkbook.ActiveSheet
' Get last row by last non-empty cell in column A
lastrw = .Cells(.Rows.Count, 1).End(xlUp).Row
' Cycle through column A
For rw = 1 To lastrw
' Highlight row with current colour
.Range("A" & rw & ":G" & rw).Interior.Color = col
' If column A value in next row is different, change colour
If .Cells(rw + 1, 1).Value <> .Cells(rw, 1) Then
' Set to whichever colour it is not
If col = col1 Then
col = col2
Else
col = col1
End If
End If
Next rw
End With
End Sub
Before:
After:
You should be able to change the font colour to red in certain cases, by inserting your own condition If .Range("F" & rw).Value = "Files ... "
etc into the main For
loop.
Upvotes: 2