# Conditional formatting

#### mpezz

##### New Member
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

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

#### Gerald Higgins

##### Well-known Member
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
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
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
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
Cleaner formula

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

#### mpezz

##### New Member
Thanks, this is what I was looking for.

#### mikerickson

##### MrExcel MVP
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.

1,106,055
Messages
5,509,053
Members
408,701
Latest member
daz457

### This Week's Hot Topics

• Turn fraction around
Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
• TIme Clock record reformatting to ???
Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
• TextBox Match
hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
• Using Large function based on Multiple Criteria
Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
• Can you check my code please
Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
• Combining 2 pivot tables into 1 chart
Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...