简体   繁体   English

根据垂直行/列值格式化单元格

[英]Formatting a cell based on perpendicular row/column values

Trying to create a Gantt chart look in Excel. 尝试在Excel中创建甘特图。 I have two columns, A and B ( A = start date, B = End Date). 我有两列,A和B( A =开始日期, B =结束日期)。

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.) 在页面顶部(第2行)我有一个列,其中包含项目每个日期的日期(为了便于阅读,自定义格式为“d”,第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. A [此行]中的值大于或等于[此列] 2。

and

the value in B[this row] less-than-or-equal-to [this column]2. B [此行]中的值小于或等于[此列] 2。

I've dug through a few answers recommending ADDRESS() and INDIRECT(), but I'm stumped on getting this to work. 我已经挖掘了一些推荐ADDRESS()和INDIRECT()的答案,但我很难接受这项工作。 Any thoughts? 有什么想法吗?

You can use AND to combine the conditions. 您可以使用AND来组合条件。 I'm assuming the 'Gantt chart' starts as from column C and the active row is 2 here. 我假设'甘特图'从C列开始,活动行在这里是2。

Select C2 and the rest of the row (to 31, 30 or 28/29 depending on the number of days in the month). 选择C2和行的其余部分(31,30或28/29,具体取决于当月的天数)。

Pull up conditional formatting with formula and put: 使用公式提取条件格式并放置:

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

Pick the format fill green and that should do it 选择格式填充绿色,应该这样做

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). 例如,如果您使用公式: =A1>5并选择单元格A1:B5 ,它将检查每个单元格以查看其> 5不仅仅是单元格A1 (因此它会自动为您增加行和列)。 Usually this is preferred over using indirect but sometimes indirect is necessary. 通常这比使用indirectindirect但有时需要indirect

So using indirect you can utilize the row() and column() functions. 因此,使用indirect可以使用row()column()函数。 So in your example: 所以在你的例子中:

the value in A[this row] is greater-than-or-equal-to [this column]2. A [此行]中的值大于或等于[此列] 2。

and

the value in B[this row] less-than-or-equal-to [this column]2. B [此行]中的值小于或等于[此列] 2。

Would look like: 看起来像:

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

Hopefully that helps 希望这会有所帮助

It works for me without ADDRESS or INDIRECT . 它适用于没有ADDRESSINDIRECT我。 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM