Hi Gary,
A change event macro usually addresses one cell (target) that is changed,
but by using the entire used range, you've covered values that
get changed in formulas as soon as a constant value is changed, or content
removed; however, unless the sheet is getting values from another sheet that
would make the Application.Volatile redundant. .
The macro will not revert to "no fill" for cells that no longer have one of the
values tested, so suggest first clearing out interior color for entire worksheet. with
cells.ColorIndex = xlNone
which is more efficient that doing one cell at a time and would remove coloring
outside of the used range.
VBA is case sensitive for most items so suggest
varValue = LCase(rngCell.Value)
On a laptop you probably want to use pastel colors to be able to view conten
anywhere on the screen, in any case one can find the color index colors
in the VBE Help (Colorindex Property) or on either
http://www.mvps.org/dmcritchie/excel/colors.htm
http://www.mvps.org//dmcritchie/excel/event.htm#case
So the changes that I would suggest are in the following area:
' On Error Resume Next '-- don't see a reason why included
' Application.Volatile '-- not likely to be needed
Set rngUsed = ActiveSheet.UsedRange
cells.ColorIndex = xlNone
For Each rngCell In rngUsed
varValue = LCase(rngCell.Value)
Question:
I know that numbers default to gray if not already getting a color but what is being
tested for True. I can understand zero and empty cells as not testing for True,
but why not text, and since numbers are treated as True why are dates and time
not also treated as True since they are numeric.
-
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages:
http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page:
http://www.mvps.org/dmcritchie/excel/search.htm