Excel Change Row color at every change in value (non consecutive)

限于喜欢 提交于 2020-06-26 05:26:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!