简体   繁体   中英

Google Apps Script to highlight a cell when a column contains specific text X number of times

I'm looking to achieve the following however am unable to with conditional formatting.

I have a sheet whereby staff will input 'Leave' on days they are on leave and 'Office Day' in days they will be in the office (other days will be WFH and not inputted).

I want to be able to highlight cells when a column has X number of 'Leave' cells (so 15 or more would be Light red, 11-14 would be orange and 10 and less would be green for example) and also highlight cells when there are X number of 'Office Days' (ie 8 or more would be dark red, 6-7 would be purple and 5 and less would be blue) so we can manage capacity.

I'm not sure if I can achieve this with a script instead?

You can do this entirely with conditional formatting. Assuming your "Leave" and "Office Day" values are in column B, you can use the following custom formulas as conditional format rules applied to all of column B:

=AND(COUNTIF(B:B, "Leave")>=15, B1="Leave")
=AND(COUNTIF(B:B, "Leave")>=11, COUNTIF(B:B, "Leave")<15, B1="Leave")
=AND(COUNTIF(B:B, "Leave")<=10, B1="Leave")
=AND(COUNTIF(B:B, "Office Day")>=8, B1="Office Day")
=AND(COUNTIF(B:B, "Office Day")>=6, COUNTIF(B:B, "Office Day")<8,B1="Office Day")
=AND(COUNTIF(B:B, "Office Day")<=5, B1="Office Day")

条件格式规则

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