Conditional Formatting on Columns based on Cell Value

I have 32 columns i am trying to have the Right border turn red, based on the value of a cell but i need it to move based on the value of the cell but only apply it to a select amount of rows in the column
For example - F2 = 21 and AO15 = 31
If A015 = F2
Then (Apply the red border to right side of AO1:AO3,AO7:AO9,AO13:AO15)
But i need this to apply from column H thru AO with the Same row numbers
So if F2 changes to say 26, then this would apply to column AJ
Would this require multiple conditions including one to undo the formatting if changed? Or could this be reduced to 2 conditions one formatting and the other for undo’ing if changed?
The grid i am working in is from H1:AP15, with Row 15 being the row the formatting will be based off, and based of the value of F2

I have built a conditional formatting that colours the right margins in the desired cells in column AO red when F2 = 31. When F2 = 26, column AJ is used. If F2 =1 column K. Column H gets the red border at -2. For explanation columns H:AP are 35 columns and not 32.

The formula is:


in array:


See also my attached example document.

dbophxlip2017.ods (8,0 KB)

I hope this fits for you.