Hi Anthon,
I see that I posted code from an experimental W/B that I was working on in
anticipation of your saying that some of the colours were quite dark and it
only has 10 colours. Here is a version that has 25 colours:
Option Explicit
Sub ColourIt()
Dim LastRow As Long
Dim cIndex As Integer
Dim Flag As Boolean
Dim cCount As Long
Dim acIndex As Variant
Dim x As Integer
acIndex = Array(3, 4, 5, 6, 7, _
8, 15, 17, 20, 22, 24, 36, 37, _
38, 39, 40, 41, 42, 43, 44, 45, 46, _
48, 50, 34)
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 WorksheetFunction.IsNA(Cells(cCount, 2).Value) Or _
WorksheetFunction.IsNA(Cells(cCount + 1, 2).Value) _
Then GoTo SkipIt
If UCase(Cells(cCount, 2).Value) = _
UCase(Cells(cCount + 1, 2).Value) Then
With Range(Cells(cCount, 2), Cells(cCount + 1, 2)).Interior
.ColorIndex = acIndex(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
Flag = False
End If
SkipIt:
Next cCount
On Error GoTo 0
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
With regard to clearing the colours it hardly seems worth while because you
only have to hightlight the Column and click on "No Fill" on the drop down
pallete of the Fill Color button but if you want to do it in code then:
Sub UnColourIt()
Range("B:B").Interior.ColorIndex = xlNone
End Sub
Will do it for you.
If you want more colours in the colouring Macro then just add more numbers
into the array. To see what the Color Index number of the various colours
are then run this Macro on an empty sheet and the Row number will be the
Color Index:
Sub Colour()
Dim cIndex As Integer
For cIndex = 1 To 56
Cells(cIndex, 1).Interior.ColorIndex = cIndex
Next cIndex
End Sub
--
HTH
Sandy
In Perth, the ancient capital of Scotland
and the crowning place of kings
[email protected]
Replace @mailinator.com with @tiscali.co.uk