Google Sheets Conditional Formatting changes when new rows added

点点圈 提交于 2019-12-19 10:33:21

问题


So I click on the cell between A and 1 to select entire sheet, then I click "Format" then "Conditional Formatting" and set the rules. Basically, I have about 15 different conditions but all are in columns F through O so I use F:O. For example, if text is exactly YES change the background to green.

The issue is when I add a new row, the formatting stops for that row and the F:O rules are replaced with F1:O15, F17:O59, etc. skipping row 16.

Can I use a script that will never change when rows are added?


回答1:


You can set up an onEdit trigger that applies the formatting every time you edit the sheet. I've provided an example of a function that would copy the format of cell A1 to all cells in the sheet. This link will bring you to Google's documentation for this type of work. https://developers.google.com/apps-script/reference/spreadsheet/range

Here's the documentation on triggers... https://developers.google.com/apps-script/guides/triggers/

function formatRange(){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("Sheet1");
  var range = sheet.getRange("A1");
  
  range.copyFormatToRange(sheet,1,sheet.getLastColumn(),1,sheet.getLastRow())
  
}


来源:https://stackoverflow.com/questions/28049119/google-sheets-conditional-formatting-changes-when-new-rows-added

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!