简体   繁体   中英

Conditional formatting based on values in current column of a Table

I have a Table with three columns:

Name Task Hours
Sheena Task1 5
Sheena Task2 3
Chris Task1 5
Chris Task1 2.5

I am trying to conditionally format the Hours column. I want to format the cells there if the total hours for the person are over 7.5 . In the example, the cells containing the hours for Sheena should be formatted because her totals are over 7.5 but Chris 's equal exactly 7.5 so should not be formatted.

I assume the formula is something along these lines:

=SUMIF([Name],INDIRECT("RC[-2]",0),[Hours])>7.5  

but this does not work. The following does:

=SUMIF($A$2:$A$5,$A2,$C$2:$E$5)>7.5  

but is messy because it doesn't use column references.

这有效:

=SUMIF(Name, INDIRECT("RC[-2]", FALSE), Hours)>7.5

The formula "something along these lines" looks very good but unfortunately Any structured reference throws an error in CF .

This goes on to mention wrapping in INDIRECT. Something like this does work:

=SUMIF(INDIRECT("Table2[Name]"),INDIRECT("RC[-2]",FALSE),INDIRECT("Table2[Hours]"))>7.5  

but in terms of messiness I think even worse than your messy:

=SUMIF($A$2:$A$5,$A2,$C$2:$E$5)>7.5  

I think @smozgur has offered an excellent "compromise" though this does involve some "behind the scenes" work. He has named the data ranges within your table as Hours and Name (hence the lack of square brackets - these are not structured references). Makes the formula look almost as you would like it but might be confusing because the range for [Hours] for example will automatically expand if new rows are added to the Table - but the named range Hours will not.

Hence my preference, assuming no conflict with data elsewhere in the columns, would be:

 =SUMIF(A:A,A1,C:C)>7.5  

_ at least it is short! (But I admit I do not like structured references.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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