Conditional formatting

mpezz

New Member
Joined
Aug 6, 2010
Messages
3
Given a range in column (e.g. containing 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4) is there a way to use conditional formatting to alternate colors for the differenet groups of values (that is: 1s in red, 2s in black, 3s in red, etc.)?
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Gerald Higgins

Well-known Member
Joined
Mar 26, 2007
Messages
9,258
Hi, welcome to the board.

I think it would be quite easy to use CF to make EVEN values black, and ODD numbers red.
Is this what you want ?
 

mpezz

New Member
Joined
Aug 6, 2010
Messages
3
Hi.
What I am looking for is a way to format the different groups, with alternate format. Data could be also text (e.g. a,a,a,a,x,x,x,y,y,y,y).
I would like to highlight blocks of contiguous data.
 

Gerald Higgins

Well-known Member
Joined
Mar 26, 2007
Messages
9,258
OK. I'm not sure how to do that with standard CF.
You could use it to apply a colour based on whether the value in the current cell is the same as the one in the previous cell, but that's not quite what you're after.
It would give you something like this
A...black
A...red
A...red
B...black
C...black
C...red

See what I mean ?
Is that any use ?
 

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
24,270
You can do this with two format contitions. Select A2 and set these formulas (and formats)

=MOD(SUMPRODUCT(--((INDEX($A:$A,1,1):INDEX($A:$A,ROW(A1),1))<>(INDEX($A:$A,2,1):INDEX($A:$A,ROW(A2),1)))),2)=0

and

=MOD(SUMPRODUCT(--((INDEX($A:$A,1,1):INDEX($A:$A,ROW(A1),1))<>(INDEX($A:$A,2,1):INDEX($A:$A,ROW(A2),1)))),2)=1

Format the colors appropriatly, these formula error in A1, so A1 should have a "natural" format the same as the =0 condition.
 

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
24,270
Cleaner formula

=MOD(SUMPRODUCT(--($A$1:INDEX($A:$A,ROW(A1),1))<>($A$2:INDEX($A:$A,ROW(A2),1)))),2)=0
 

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
24,270
You could select cell A2 and set these two CF formulas

Condition 1:
=(1=MOD(SUMPRODUCT(--($A$1:$A1<>$A$2:$A2)),2))

Condition 2:
=True

and copy the formatting to the other cells as needed.
 

Forum statistics

Threads
1,176,149
Messages
5,901,628
Members
434,908
Latest member
Mati

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
Top