Alternating Colors For Excel Based on Cell Value

austinandrei

Board Regular
Joined
Jun 7, 2014
Messages
117
Hi,
Can it be possible to have a quick way to have an alternating color pattern in excel rows depending on the cell value?
Say I have these examples from Cell A1 to A9 with A1 as the header:

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]THIS IS THE HEADER IN CELL A1[/TD]
[/TR]
[TR]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl65, width: 110"]10000123[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl65, width: 110"]10000123[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl65, width: 110"]27298951-000001[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl65, width: 110"]30004240[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl65, width: 110"]30004240[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl65, width: 110"]30004240[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl65, width: 110"]50000495[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl65, width: 110"]50000495[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]

Then Cell A2 to A3 will have the 1st color pattern then Cell A4 will have the 2nd color pattern then Cells A5 to Cell A7 will have again the 1st color pattern then Cell A8 to A9 will have the 2nd color pattern, thus alternating colors for duplicate cell values in Column A. Data will be sorted first as always, thus duplicate values will always stick together to have the same color pattern.

Thanks in advance for the help!
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
I usually do it like this. Use a vacant column to fill
- The row 1 cell manually with a 1
- Row 2 formula copied down as far as you might need then hide this formula column.

Select A2 to the bottom right of the range you might want coloured & apply the Conditional Formatting formulas shown.

Excel Workbook
AB
1Hdr1
2a-1
3a-1
4a-1
5a-1
6b1
7b1
8c-1
9c-1
10c-1
11d1
12e-1
13f1
14g-1
15g-1
16g-1
171
181
19h-1
20h-1
21
22
Cond Format In Groups
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A21. / Formula is =$B2=-1Abc
A22. / Formula is =$B2=1Abc
 
Last edited:
Upvote 0
Peter,

I too would like to thank you for your post- your method works perfectly for me too.

just a curiosity question; IS there a way to do this without a helper column? I imagine it would be quite convoluted if so....

regards,

blbat
 
Upvote 0
Peter,

I too would like to thank you for your post- your method works perfectly for me too.

just a curiosity question; IS there a way to do this without a helper column? I imagine it would be quite convoluted if so....

regards,

blbat
You're welcome.

Yes, you can do this without the helper but it will be considerably more resource-hungry

Excel Workbook
A
1Hdr
2a
3a
4a
5a
6b
7b
8c
9c
10c
11d
12e
13f
14g
15g
16g
17
18
19h
20h
CF in Groups
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A21. / Formula is =MOD(SUMPRODUCT(--($A$1:$A1<>$A$2:$A2)),2)=1Abc
A22. / Formula is =MOD(SUMPRODUCT(--($A$1:$A1<>$A$2:$A2)),2)=0Abc
 
Upvote 0
Very Nice Peter...

I know what the Doulbe Unary Operator does, but have never become adept at it's use.
 
Upvote 0
You're welcome :)

(The mikerickson suggestion did not work for me)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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