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:

THIS IS THE HEADER IN CELL A1
10000123

<tbody>
</tbody>
10000123

<tbody>
</tbody>
27298951-000001

<tbody>
</tbody>
30004240

<tbody>
</tbody>
30004240

<tbody>
</tbody>
30004240

<tbody>
</tbody>
50000495

<tbody>
</tbody>
50000495

<tbody>
</tbody>

<tbody>
</tbody>

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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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,214,641
Messages
6,120,695
Members
448,979
Latest member
DET4492

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