Hi there,
The amended code shades the cells as requested - just change the colour to suit.
There's no inherent function to sort by colour in Excel, but fortunately this User Defined Function (UDF) does the job.
HTH
Robert
Sub ShadeParticularCells()
Dim lngLastRow As Long
'Find the last row and assign it to the 'lngLastRow' variable _
based on Column A (change as required).
lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row
'Assumes the data is in Column A and starts at row 1 (change as required).
For Each cell In Range("A1:A" & lngLastRow)
'If the current cell has '04' in it, then...
If InStr(cell, "04") > 0 Then
'Check if the active cell has any shading. _
If it doesn't then...
If cell.Interior.ColorIndex = xlNone Then
'...shade the cell in yellow (change colour to suit).
cell.Interior.ColorIndex = 6
End If
End If
'If the current cell has '05' in it, then...
If InStr(cell, "05") > 0 Then
'Check if the active cell has any shading. _
If it doesn't then...
If cell.Interior.ColorIndex = xlNone Then
'...shade the cell in orange (change colour to suit).
cell.Interior.ColorIndex = 46
End If
End If
'If the current cell has '06' in it, then...
If InStr(cell, "06") > 0 Then
'Check if the active cell has any shading. _
If it doesn't then...
If cell.Interior.ColorIndex = xlNone Then
'...shade the cell in blue (change colour to suit).
cell.Interior.ColorIndex = 5
End If
End If
'If the current cell has '07' in it, then...
If InStr(cell, "07") > 0 Then
'Check if the cell beneath it has any shading. _
If it doesn't and it's not blank (empty), then...
If cell.Offset(1, 0).Interior.ColorIndex = xlNone And _
IsEmpty(cell.Offset(1, 0)) = False Then
'...shade the cell in green (change colour to suit).
cell.Offset(1, 0).Interior.ColorIndex = 10
End If
End If
Next cell
End Sub
Bookmarks