Conditional formatting for more than five in a row - Is there a better way?

Jayem1

New Member
Joined
Dec 18, 2013
Messages
7
Hello,

I have a column of a 1,000 randomly generated numbers where each cell shows one of two results, "1" or "-1".
I want to highlight only the cells that contain the same results of 5 or more in a row.

I also want to be able to highlight higher amounts like 8, 12 or 20 in a row.

Currently I have this formula for 5 in a row:


=OR(AND(A5=A1, A5=A2, A5=A3, A5=A4, A5=A5), AND(A5=A2, A5=A3, A5=A4, A5=A5, A5=A6), AND(A5=A3, A5=A4, A5=A5, A5=A6, A5=A7), AND(A5=A4, A5=A5, A5=A6, A5=A7, A5=A8), AND(A5=A5, A5=A6, A5=A7, A5=A8, A5=A9))


I want to know if there is a better way to do it or do I just use this basic format and keep building it out for the larger consecutive amounts I need?

Thank you.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hi

I'd use in A1 the formula:

=MAX(IF(ROW(A1)-ROW(INDIRECT("1:5"))>=0,COUNTIF(OFFSET(A1,1-ROW(INDIRECT("1:5")),0,5),A1)))=5

and copy the format down
 
Upvote 0
Thank you that works perfectly. I have a few clarifications and a couple more variables to ask about.


1. If my data starts at 'B8' is it correct to change all occurrences in the formula of 'A1' to 'B8'?


2. Is it correct to assume that if I want to format consecutive repeats of 9-in-a-row (instead of 5) that I just change all the occurrences in the formula of '5' to an '8'?


3. Is there a way to change it to only format occurrences of 5-in-a-row but no more than that?


4. I have an issue with back to back occurrences of five "1"'s in-a-row followed by five "-1"'s in-a-row showing up as one large highlighted block so I want to format the groups of "1"'s in one color and the groups of "-1"'s in another. Can we tell the formula to only highlight five "1"s in a row? I would like to be able to do that for both current formula of five or more and for the new formula of just five in-a-row if possible.



Thank you again this is great help.
 
Upvote 0

Forum statistics

Threads
1,215,350
Messages
6,124,431
Members
449,158
Latest member
burk0007

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