问题
In Excel, I want to change the color of the row at every change in a particular row value. The changed rows could be non-consecutive.
For example:
Customer Product Line Product
1 Outdoor Lawn Jarts
1 Indoor Nerf Hoops
2 Outdoor Ball Game
3 Indoor Fort Builder
4 Indoor Twist'Em
4 Indoor Silly Silly
In this example, I would want customer 1 to be light blue; customer 2, white; customer 3 light blue; customer 4, white, repeating at every customer change.
I'd prefer to use a formula if possible. Thanks.
EDIT: Customer numbers are non-consecutive numbers (1,15,49406, etc.)
回答1:
Starting in A2, highlight the Range A2:C7 (Or whatever range necessary) and then create a New Rule in the Conditional Formatting Rules Manager. Select "Use a formula to determine which cells to format" and enter this formula:
=MOD(SUM(IF(FREQUENCY($A$2:$A2,$A$2:$A2)>0,1)),2)=1
If the customer numbers include text, you can use:
=MOD(SUM(IF(FREQUENCY(MATCH($A$2:$A2,$A$2:$A2,0),MATCH($A$2:$A2,$A$2:$A2,0))>0,1)),2)=1
回答2:
Add a new column like this:
In D2
just put the literal string "Blue". Then in D3
put the formula
=IF(A3<>A2,IF(D2="Blue","White","Blue"),D2)
And translate down.
On the entire sheet place a conditional format with the rule
=INDEX($D:$D,ROW()) = "Blue"
You can then hide column D if you want:
来源:https://stackoverflow.com/questions/32254209/excel-change-row-color-at-every-change-in-value-non-consecutive