ClimoC
Well-known Member
- Joined
- Aug 21, 2009
- Messages
- 584
Hello
I have a range of data which I want colour-coded if the date in a cell is different to the one above it.
If it is the same as the date above it, I want the colour to be the same as that cell.
The below macro almost works - it scans the range, and if the cell above it is different to its date, the cell changes colour. However, the next cell beneath that (which might happen to share the same date) doesn't change.
Also if possible I'd like to be colouring all rows but only in the array G6:L500 and not the columns outside this array.
here is my code
ANy help would be MUCH appreciated.
Cheers
I have a range of data which I want colour-coded if the date in a cell is different to the one above it.
If it is the same as the date above it, I want the colour to be the same as that cell.
The below macro almost works - it scans the range, and if the cell above it is different to its date, the cell changes colour. However, the next cell beneath that (which might happen to share the same date) doesn't change.
Also if possible I'd like to be colouring all rows but only in the array G6:L500 and not the columns outside this array.
here is my code
Code:
Sub colourme()
Dim r As Range
Dim c As Range
Dim rw As Range
Set r = Range("Schedule!G6:G500")
Set rw = r.Rows
For Each rw In r
If rw.Offset(-1, 1).Value = rw.Offset(0, 1).Value Then
rw.Interior.ColorIndex = rw.Offset(-1, 1).Interior.ColorIndex
ElseIf rw.Offset(-1, 1).Value <> rw.Offset(0, 1).Value Then
rw.Interior.ColorIndex = 7
End If
Next
End Sub
ANy help would be MUCH appreciated.
Cheers