BipedalMammal
BipedalMammal

Reputation: 23

Formatting a cell based on perpendicular row/column values

Trying to create a Gantt chart look in Excel. I have two columns, A and B (A = start date, B = End Date).

Across the top of the page (Row 2) I have a column with a date for every date of the project (custom formatted with "d" for readability, with the name of the month in Row 1.)

I'm now trying to apply conditional formatting rules to turn the cell in the column a specific colour (say, green) if:

the value in A[this row] is greater-than-or-equal-to [this column]2.

and

the value in B[this row] less-than-or-equal-to [this column]2.

I've dug through a few answers recommending ADDRESS() and INDIRECT(), but I'm stumped on getting this to work. Any thoughts?

Upvotes: 0

Views: 3481

Answers (3)

Robert Co
Robert Co

Reputation: 1715

It works for me without ADDRESS or INDIRECT. This is the formula inside the conditional formatting. If I have to guess what's going on, it's most likely that you are not placing the proper anchors ($).

=AND(C$2>=$A3,C$2<=$B3)

Upvotes: 0

chancea
chancea

Reputation: 5968

In conditional formatting if you use the first cell of your selection in the formula it automatically turns that into a relative formula.

For example if you use the formula: =A1>5 and select cells A1:B5 it will check each cell to see if its >5 not just cell A1 (so it automatically increments the row and the column for you). Usually this is preferred over using indirect but sometimes indirect is necessary.

So using indirect you can utilize the row() and column() functions. So in your example:

the value in A[this row] is greater-than-or-equal-to [this column]2.

and

the value in B[this row] less-than-or-equal-to [this column]2.

Would look like:

=AND(INDIRECT("A"&ROW()) >= INDIRECT(CHAR(COLUMN()+64)&"2"), INDIRECT("B"&ROW()) <= INDIRECT(CHAR(COLUMN()+64)&"2"))

Hopefully that helps

Upvotes: 1

Jerry
Jerry

Reputation: 71578

You can use AND to combine the conditions. I'm assuming the 'Gantt chart' starts as from column C and the active row is 2 here.

Select C2 and the rest of the row (to 31, 30 or 28/29 depending on the number of days in the month).

Pull up conditional formatting with formula and put:

=AND(C2>=$A2,C2<=$B2)

Pick the format fill green and that should do it

Upvotes: 1

Related Questions