Sub sortcolour()
'Brian Warnock December 2005
'Sort rows by colour index
Dim lnglastrow As Long
Dim lnglastcol As Long
Dim lnglastcol2 As Long
lnglastrow = ActiveSheet.UsedRange.Rows.Count
lnglastcol = ActiveSheet.UsedRange.Columns.Count
lnglastcol2 = lnglastcol + 1
For Each c In Range(Cells(1, lnglastcol), Cells(lnglastrow, lnglastcol))
c.Offset(0, 1).Value = c.Interior.ColorIndex
Next c
ActiveSheet.Range(Cells(1, 1), Cells(lnglastrow, lnglastcol2)).Sort _
key1:=ActiveSheet.Cells(1, lnglastcol2), order1:=xlDescending
ActiveSheet.Cells(1, lnglastcol2).EntireColumn.Delete
End Sub