Color code every other group of cells

toddlerzz

Board Regular
Joined
Oct 21, 2007
Messages
53
I need to color code a group of cells every time a value changes.

For example, in column A, I have the word Truck in the first 5 cells, then the word Horse in the next 5 cells, then the word Plane in the next 8 cells, etc.

I need a formula to color cod each group of cells whenever the value changes, it can be just two colors, Truck could be blue, then Horse could be no color, Plane would be blue, next word would be no color, I just need something to differentiate each block when the text changes.

Thanks,
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
NOTE
- method below assumes that each "group" of words is unique (ie there is only one group of dogs, one fleet of planes etc!)


Excel 2016 (Windows) 32 bit
A
B
C
D
E
F
G
H
I
J
K
L
M
N
1
catcatdogdogdogplaneplaneplaneplaneplanepearpearpearpear
2
3
1​
1​
2​
2​
2​
3​
3​
3​
3​
3​
4​
4​
4​
4​
4
TRUE​
TRUE​
FALSE​
FALSE​
FALSE​
TRUE​
TRUE​
TRUE​
TRUE​
TRUE​
FALSE​
FALSE​
FALSE​
FALSE​
Sheet: Sheet1


1. Explanation
The formula in rows 3 & 4 are there so that you can see how this works

To get cumulative count of unique values starting at A1
- in A3 copied across
=SUMPRODUCT(1/COUNTIF($A$1:A$1,$A$1:A$1&""))

Convert those value to TRUE\False by wrapping above formula in ISODD
- in A4 copied across
=ISODD(SUMPRODUCT(1/COUNTIF($A$1:A$1,$A$1:A$1&"")))

2. Apply conditional formatting using formula in A4


Select row 1

click on Home tab
click on Conditional Formatting
click on New Rule
click on Use a formula to determine which cells to format
paste formula =ISODD(SUMPRODUCT(1/COUNTIF($A$1:A$1,$A$1:A$1&""))) into box under Format values where this formula is true
click on Format
above example was formatted by clicking on Font and changing Color to red

Conditional Formatting can be tricky
- the formula must be correct for the leftmost cell in the range you are formatting
- I suggest you copy what I did EXACTLY (including putting the values in row 1)
- you can then insert rows above or columns to left of data and Excel auto-adjusts
- otherwise you need to amend the formula before trying to use it in conditional formatting
 
Upvote 0
Oops :oops:
- I applied to row1 instead of column A
- will update thread shortly
 
Upvote 0
1. Same method as above except the formula is now
=ISODD(SUMPRODUCT(1/COUNTIF($A$1:$A1,$A$1:$A1&"")))

2. Apply conditional formatting using formula above
Select Column A
click on Home tab
click on Conditional Formatting
click on New Rule
click on Use a formula to determine which cells to format
paste formula =ISODD(SUMPRODUCT(1/COUNTIF($A$1:$A1,$A$1:$A1&""))) into box under Format values where this formula is true
click on Format
above example was formatted by clicking on Font and changing Color to red

Excel 2016 (Windows) 32 bit
A
1
cat
2
cat
3
dog
4
dog
5
dog
6
plane
7
plane
8
plane
9
plane
10
plane
11
pear
12
pear
13
pear
14
pear
15
Sheet: Sheet1
 
Upvote 0
Another way, perhaps a little simpler, also uses a helper row, and again assumes your data is pre-sorted, with no "split" groups

In A3, enter the single value
1

In B3
=if(B1=A1,A3,-A3)

And copy across.

This will give you a sequence of 1 and -1, which flips from 1 to -1 each time the data in A1 changes.
Then apply Conditional Formating, based on whether the value in row 3 = 1 or -1.

Edit to add - this assumes your data is laid out as in post #2 , in a ROW.
Just noticed, the OP said you had data in a column.
This (and Yongle's) solution can easily be adapted to a column - post back if you need help with that.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,532
Messages
6,114,177
Members
448,554
Latest member
Gleisner2

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