Conditional formatting based on several cell values

alecambo

New Member
Joined
Apr 10, 2015
Messages
35
Office Version
  1. 2021
Platform
  1. Windows
Good day! I have dataset that looks like this (let's assume that "Name" is column A and "Sequence" is column B):
[TABLE="width: 500"]
<tbody>[TR]
[TD]Name[/TD]
[TD]Sequence[/TD]
[/TR]
[TR]
[TD]BUNNY[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]BUNNY[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]BUNNY[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]BUNNY[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]TIGER[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]TIGER[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]TIGER[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]TIGER[/TD]
[TD]-[/TD]
[/TR]
[TR]
[TD]DOG
[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]DOG
[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]DOG
[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]DOG
[/TD]
[TD]2[/TD]
[/TR]
</tbody>[/TABLE]

I am in the need of a simple formula highlights the 4 "Sequence" cells in red when the sequence for each "Name" is any different from the two following sequences: "1 ,2, 3, 4" or "1, 2, 3, -": in the given example, DOG should turn red since the sequence is different from the two allowed ones.

Thanks in advance,

Alejandro
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Will there always be four numbers for each animal?
If not, what happens if you get this sequence

BUNNY 1
BUNNY 1
BUNNY 2
BUNNY 3
BUNNY 4

I see TWO four number sequences, the 1234 you've stated starting at row 2 and 1123 starting at row 1
1123 is not a valid sequence so should that be highlighted?
 
Last edited:
Upvote 0
Will there always be four numbers for each animal?
If not, what happens if you get this sequence

BUNNY 1
BUNNY 1
BUNNY 2
BUNNY 3
BUNNY 4

I see TWO four number sequences, the 1234 you've stated starting at row 2 and 1123 starting at row 1
1123 is not a valid sequence so should that be highlighted?

You are correct, there will always be four numbers for each animal.
 
Upvote 0
We can do this with a helper column, there may be a way with array formulas to avoid the helper column, though I cant see it at the moment.

in C2
=(COUNTIF(A$2:A2,A2)=B2)*1
and copy down the column

Then
Select the range to highlight

Conditional Formatting
New Rule
Use a formula to determine...

=AND(A2<>"",SUMIF(A$2:A$1000,A2,C$2:C$1000)=4)

Format as red
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,205
Members
452,618
Latest member
Tam84

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