Bernie Deitrick said:
Sandy,
Your code works very well, so I'll take a pass on trying to do my own
version.
No it doesn't! I wrote half of it last night and then when I saw that it
still hadn't been finally answered this morning I quickly finished it off
and posted it. After posting I noticed that I had left a line in that I had
intended to change because it changed the Color Index at each Successful IF
instead of the Unsuccessful ones but I have not been able to get back on
line until now. How frustrating!!!!
Anyway here is the corrected code:
Option Explicit
Sub ColourIt()
Dim LastRow As Long
Dim cIndex As Integer
Dim Flag As Boolean
Dim cCount As Long
LastRow = Cells(Rows.Count, 2).End(xlUp).Row
Application.ScreenUpdating = False
Columns("C:C").Insert Shift:=xlToRight
Range("C1").Value = 1
Range(Cells(1, 3), Cells(LastRow, 3)) _
.DataSeries Rowcol:=xlColumns, _
Type:=xlLinear, Date:=xlDay, _
Step:=1, Trend:=False
With Range(Cells(1, 1), Cells(LastRow, 3))
.Sort Key1:=Range("B1"), _
Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom
End With
Flag = False
cIndex = 3
For cCount = 1 To LastRow
If Cells(cCount, 2).Value = Cells(cCount + 1, 2).Value Then
With Range(Cells(cCount, 2), Cells(cCount + 1, 2)).Interior
.ColorIndex = cIndex
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Flag = True
End If
If Cells(cCount, 2).Value <> Cells(cCount + 1, 2).Value _
And Flag = True Then cIndex = cIndex + 1
Next cCount
With Range(Cells(1, 1), Cells(LastRow, 3))
.Sort Key1:=Range("C1"), _
Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom
End With
Columns("C:C").Delete Shift:=xlToLeft
Range("B1").Select
Application.ScreenUpdating = True
End Sub
--
HTH
Sandy
In Perth, the ancient capital of Scotland
and the crowning place of kings
(e-mail address removed)
Replace @mailinator.com with @tiscali.co.uk