I have a bas file with lots of functions related to colors at
http://www.cpearson.com/Excel/Colors.aspx. You can use the
RangeOfColor function to return a Range object whose background or
font ColorIndex is some specific value and then draw the border around
the returned range. The code is explained on the page noted above, and
the downloadable module file is at
http://www.cpearson.com/Zips/modColorFunctions.zip .
Using RangeOfColor, you can use code like the following:
Sub AAA()
Dim R As Range
' Red
Set R = RangeOfColor(TestRange:=ActiveSheet.UsedRange, _
ColorIndex:=3, OfText:=False)
If Not R Is Nothing Then
R.BorderAround LineStyle:=xlSolid, Weight:=xlThick
End If
' Yellow
Set R = Nothing
Set R = RangeOfColor(TestRange:=ActiveSheet.UsedRange, _
ColorIndex:=6, OfText:=False)
If Not R Is Nothing Then
R.BorderAround LineStyle:=xlSolid, Weight:=xlThick
End If
' Blue
Set R = Nothing
Set R = RangeOfColor(TestRange:=ActiveSheet.UsedRange, _
ColorIndex:=5, OfText:=False)
If Not R Is Nothing Then
R.BorderAround LineStyle:=xlSolid, Weight:=xlThick
End If
End Sub
Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)