Color Rows by Criteria
Since this was originally written in 1994, there have been continual changes. It was written for Excel 3.0 macro language; updated for versions 4.0 and 5.0 and tweaked to run as 4.0 language in 7.0.When my friend eventually got me to convert to VBA, this was one of the first things I did. The app is now part of a comprehensive toolkit that I have been building for my workgroup. In it’s current iteration, I use a userform to present a list of color names (some from Excel and others from my own observation). It highlighted and formatted a 10,000 row table in mere seconds. [1.5 GB RAM]
Sub ColorRows()
Dim I As Integer, Color As Integer, LastRow As Integer
Dim daColors As String
Dim BottomRw, LastCol, ColorNames, ColorNumbs, ColorCode As Long
Unload usrColorRows
ColorNames = Array("Red", "Bright Green", "Blue", "Yellow", "Pink", "Aqua", "Olive", "Teal", "Grey 25%", "Grey 40%", _
"Grey 50%", "Purple", "Plum", "Maize", "Light Blue", "Light Purple", "Fushia", "Bright Yellow", "Light Blue", _
"Light Turquoise", "Light Green", "Light Yellow", "Pale Blue", "Rose", "Lavender", "Tan", "Aqua", "Lime", _
"Gold", "Light Orange", "Orange", "Brown")
ColorNumbs = Array(2, 3, 4, 5, 6, 7, 11, 13, 14, 47, 15, 16, 17, 18, 19, 23, 25, 26, 32, _
33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 52)
With usrColorRows.cmbColors
For I = LBound(ColorNumbs) To UBound(ColorNumbs)
.AddItem ColorNumbs(I) & " =" & ColorNames(I)
Next
End With
usrColorRows.Show
ColorCode = Left(usrColorRows.cmbColors.Value, 2) + 1
Range("A2").Select
'---------
LastRow = ActiveCell.SpecialCells(xlLastCell).Row
LastCol = ActiveCell.SpecialCells(xlLastCell).Column
ActiveSheet.Range(Cells(1, 1), Cells(LastRow, LastCol)). _
Interior.ColorIndex = xlNone
For I = 2 To LastRow Step 2
ActiveSheet.Range(Cells(I, 1), Cells(I, LastCol)). _
Interior.ColorIndex = ColorCode
Next
ActiveSheet.Range(Cells(2, 1), Cells(LastRow, LastCol)).Select
With Selection.Borders(xlLeft)
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlRight)
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlTop)
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlBottom)
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection
.BorderAround Weight:=xlThin, ColorIndex:=xlAutomatic
End With
Columns("A:IV").Select
With Selection
.Columns.AutoFit
End With
Range("A1").Select
Unload usrColorRows
End Sub
You would think that you could simply start counting the colors in the toolbar and arrive at the exact number for each color. I found out differently. If you ’customize‚ the colors, Excel still reports the color name that was originally there.
|