I have a table in an Excel worksheet where the rows are generally grouped
(perhaps sorted) by the value in one column.
In the below example, it is Column A
and it is sorted by Year.
But it's not necessarily numeric and it's not necessarily sorted;
it could be "Apple", "Apple", "Apple", "Pear", "Banana", "Banana".
I'd like to change the fill color for the row when the value in the designated column changes. For example:
A | B | C | ||
---|---|---|---|---|
1 | Year | Name | Amount | |
2 | 1999 | Fred | 1,000 | (this row should be orange) |
3 | 1999 | Alice | 1,200 | (this row should be orange) |
4 | 1999 | Bob | 100 | (this row should be orange) |
5 | 2000 | Carol | 250 | (this row should be green) |
6 | 2001 | David | 450 | (this row should be orange) |
7 | 2001 | Ed | 600 | (this row should be orange) |
8 | 2002 | Joe | 700 | (this row should be green) |
So the fill for the rows with 1999 in the Year column would be one color, say orange, then when the value changes, the fill color changes. It would be fine if the color just alternated, say orange then green then orange, etc. I'm interested in a general way of doing it, not something that relies on the column being years or a number, it could be a car make, or a fruit, etc. Also, if there's another year 1999 many rows down, it need not be fill color 1, it just has to be different from the non-1999 rows adjacent to it.
I've used conditional formatting for several things but I can't get it to do this. The purpose is to be able to better see when the year changes. This is different from just alternating the fill.
VBA
to the question.