Conditional if in multiple rows and columns

alecambo

New Member
Joined
Apr 10, 2015
Messages
35
Office Version
  1. 2021
Platform
  1. Windows
Greetings! I have a question that I believe it should be fairly easy to resolve for someone with experience. I have a data set that looks something like this:

RunOrderSequence
CAR12
CAR21
CAR33
CAR44
APPLE12
APPLE21
APPLE33
APPLE4-
SODA11
SODA24
SODA33
SODA42

<tbody>
</tbody>

As you can see, the order always remains constant for each Run (1, 2, 3, 4), and the Runs always consist of 4 steps. What is variable is the sequence, which can take any of the following values: "-", "1", "2", "3", "4".

That being said, I need a formula that highlights the 4 "Run" cells in red when the sequence for that Run is any different from the two following sequences: "2 ,1, 3, 4" or "2, 1, 3, -":
Run
Order
Sequence
CAR12
CAR21
CAR33
CAR44
APPLE12
APPLE21
APPLE33
APPLE4-

<tbody>
</tbody>



For instance, this would be an invalid Run since it doesn't follow any of the two admitted sequences "2 ,1, 3, 4" or "2, 1, 3, -".
RunOrderSequence
SODA
13
SODA
24
SODA
31
SODA
42

<tbody>
</tbody>

I appreciate any help you may provide. Thanks in advance,

Ale
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
If you're using Excel 2016 (when the TEXTJOIN function was introduced) or later:

1) select cells B3 through B14 (or whatever the end of your range is).

2) Go to conditional formatting -- > new rule

3) Select "use a formula to determine which cells to format"

4) in the "Format values where this formula is true" box, enter this (adjusting the $B$14 and $D$14 to be the end of your ranges as necessary):

Code:
=NOT(OR(TEXTJOIN("|",,IF($B$3:$B$14=B3,$D$3:$D$14,""))="2|1|3|4",TEXTJOIN("|",,IF($B$3:$B$14=B3,$D$3:$D$14,""))="2|1|3|-"))

5) Click "Format" and change the Font color (on the font tab) to be red.

6) Click OK twice.
 
Upvote 0
Another option which doesn't require TEXTJOIN.

I'm assuming that the "Run" column is A, the "Sequence" column is C, and there is 1 header row, so the first row of data is 2. Given that, select column A, click Conditional Formatting > New Rule > Use a formula > and enter:

=IF(A1="",0,IF(INDEX(C:C,ROW()-MOD(ROW()-2,4))&INDEX(C:C,ROW()-MOD(ROW()-2,4)+1)&INDEX(C:C,ROW()-MOD(ROW()-2,4)+2)="213",0,1))

Click Format... and choose your fill color.
 
Upvote 0
Thank you both for posting these answers. Right now I'm away from my work computer but I'm going to test both answers as soon as I can.

Best,
Ale
 
Upvote 0
I've tried both answers and they seem to work just fine.

If anyone else is interested on sharing their take on the matter, I'll gladly accept it.

Thanks,
Ale
 
Upvote 0

Forum statistics

Threads
1,214,415
Messages
6,119,377
Members
448,888
Latest member
Arle8907

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