Conditional formatting: color rows with with shade when rows have the same value in their respective first cell

flashgordie

Board Regular
Joined
Jan 9, 2008
Messages
95
Office Version
  1. 365
Platform
  1. Windows
Is it possible for conditional formatting to evaluate the first cell of a row, compare it to the first cell of the next row, and if =, then look to next row and so on? When they are equal, I would like it to colour the rows the rows that have the same first cell and only the rows that touch each other. In the example below, apple is shaded two different colors.

1706652612160.png
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
For the future, you will get faster/better help if you could provide your sample data with XL2BB so we can easily copy for testing. :)


If you want to have many different colours like that it is more difficult so for a start would colour banding like this be any use to you?

24 01 31.xlsm
ABC
1ProductCrateTruck
2apple
3apple
4pear
5pear
6mango
7mango
8apple
9banana
10banana
11grape
12lime
13lime
14lime
CF Bands
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A2:C14Expression=ISEVEN(SUMPRODUCT(--($A$2:$A2<>$A$1:$A1)))textNO
A2:C14Expression=ISODD(SUMPRODUCT(--($A$2:$A2<>$A$1:$A1)))textNO
 
Upvote 0
You could increase the number of colours before repeat at least a bit more fairly easily. Here I have used 4 colours instead of 2. It is just a matter of copying the formula, pasting into a new rule and changing the final number in the formula.

24 01 31.xlsm
ABC
1ProductCrateTruck
2apple
3apple
4pear
5pear
6mango
7mango
8apple
9banana
10banana
11grape
12lime
13lime
14lime
CF Bands (2)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A2:C14Expression=MOD(SUMPRODUCT(--($A$2:$A2<>$A$1:$A1)),4)=3textNO
A2:C14Expression=MOD(SUMPRODUCT(--($A$2:$A2<>$A$1:$A1)),4)=2textNO
A2:C14Expression=MOD(SUMPRODUCT(--($A$2:$A2<>$A$1:$A1)),4)=1textNO
A2:C14Expression=MOD(SUMPRODUCT(--($A$2:$A2<>$A$1:$A1)),4)=0textNO
 
Upvote 0
You could increase the number of colours before repeat at least a bit more fairly easily. Here I have used 4 colours instead of 2. It is just a matter of copying the formula, pasting into a new rule and changing the final number in the formula.

24 01 31.xlsm
ABC
1ProductCrateTruck
2apple
3apple
4pear
5pear
6mango
7mango
8apple
9banana
10banana
11grape
12lime
13lime
14lime
CF Bands (2)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A2:C14Expression=MOD(SUMPRODUCT(--($A$2:$A2<>$A$1:$A1)),4)=3textNO
A2:C14Expression=MOD(SUMPRODUCT(--($A$2:$A2<>$A$1:$A1)),4)=2textNO
A2:C14Expression=MOD(SUMPRODUCT(--($A$2:$A2<>$A$1:$A1)),4)=1textNO
A2:C14Expression=MOD(SUMPRODUCT(--($A$2:$A2<>$A$1:$A1)),4)=0textNO
Thank you so much for your reply and yes, I realize now including the xl2bb code makes sense. so with that, please see below. I can certainly work with two colors. And your solution works for the information that I provided, but I should have considered how may data is structured. I am pulling the viewing data that I would like colored from another sheet which holds the source data, so my values are actually spilled formula based on conditions.

Would you have any suggestions for that type of situation? Thank you!!!!



mr excel example.xlsx
ABCDEFGHIJKLMNOP
1 I would like the formatting applied to the viewing data however it contains formulas that are pulling from the source data which is on another sheet and pulling it based on a conditions so it viewing data and source data will not always be equal.
2
3Viewing DataSource data
4IDProductCrateTruckIDProductCrateTruck
510001applef310001applef3
610001applee710001applee7
712011pearz512011pearz5
812011pearn512011pearn5
912056Mangod312056Mangod3
1012056Mangoe212056Mangoe2
1112101Blueberrya612101Blueberrya6
1213444Bananak113444Bananak1
1313444Bananar113444Bananar1
1413501Grapeh213501Grapeh2
1516222Limef416222Limef4
1616222Limee416222Limee4
1716222Limeq116222Limeq1
Sheet2
Cell Formulas
RangeFormula
A5:D17A5=J5:M17
Dynamic array formulas.


1706706080340.png
 
Upvote 0
Thanks for the XL2BB sample data. (y)

I assume that you are saying the spill range could be more or less rows and/or more or less columns that the example shown.
If so, see if this could work for you. Decide on a maximum possible range that the spill could fill & select that to apply the Conditional Formatting to. In my mini sheet below I decided on A5:H25 as the maximum possible range and applied the given CF to that range. This effectively give two-colour banding. If you actually wanted something other than white as the second colour, or more than two colours that could still be achieved.
After applying this CF, try changing the A5 formula to, say =J7:K15

flashgordie.xlsm
ABCDEFGHIJKLMN
3Viewing DataSource data
4IDProductCrateTruckIDProductCrateTruck
510001applef310001applef3
610001applee710001applee7
712011pearz512011pearz5
812011pearn512011pearn5
912056Mangod312056Mangod3
1012056Mangoe212056Mangoe2
1112101Blueberrya612101Blueberrya6
1213444Bananak113444Bananak1
1313444Bananar113444Bananar1
1413501Grapeh213501Grapeh2
1516222Limef416222Limef4
1616222Limee416222Limee4
1716222Limeq116222Limeq1
18
19
20
21
22
23
24
25
Sheet1
Cell Formulas
RangeFormula
A5:D17A5=J5:M17
Dynamic array formulas.
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A5:H25Expression=AND(ROWS($A$5#)>=ROW(A5)-ROW($A$5)+1,COLUMNS($A$5#)>=COLUMN(A5)-COLUMN($A$5)+1,MOD(SUMPRODUCT(--($A$5:$A5<>$A$4:$A4)),2))textNO
 
Upvote 1
Solution
Thanks for the XL2BB sample data. (y)

I assume that you are saying the spill range could be more or less rows and/or more or less columns that the example shown.
If so, see if this could work for you. Decide on a maximum possible range that the spill could fill & select that to apply the Conditional Formatting to. In my mini sheet below I decided on A5:H25 as the maximum possible range and applied the given CF to that range. This effectively give two-colour banding. If you actually wanted something other than white as the second colour, or more than two colours that could still be achieved.
After applying this CF, try changing the A5 formula to, say =J7:K15

flashgordie.xlsm
ABCDEFGHIJKLMN
3Viewing DataSource data
4IDProductCrateTruckIDProductCrateTruck
510001applef310001applef3
610001applee710001applee7
712011pearz512011pearz5
812011pearn512011pearn5
912056Mangod312056Mangod3
1012056Mangoe212056Mangoe2
1112101Blueberrya612101Blueberrya6
1213444Bananak113444Bananak1
1313444Bananar113444Bananar1
1413501Grapeh213501Grapeh2
1516222Limef416222Limef4
1616222Limee416222Limee4
1716222Limeq116222Limeq1
18
19
20
21
22
23
24
25
Sheet1
Cell Formulas
RangeFormula
A5:D17A5=J5:M17
Dynamic array formulas.
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A5:H25Expression=AND(ROWS($A$5#)>=ROW(A5)-ROW($A$5)+1,COLUMNS($A$5#)>=COLUMN(A5)-COLUMN($A$5)+1,MOD(SUMPRODUCT(--($A$5:$A5<>$A$4:$A4)),2))textNO
Thank you so much Peter_SSs
. Its a piece of art and works beautifully!!! Very much appreciate the help.
 
Upvote 0
You're welcome. Thanks for the follow-up. :)
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,975
Members
449,095
Latest member
Mr Hughes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top