我在Google Drive電子表格中包含一個簡單的電子表格,其中包含colA中的一個名稱列表。 ColB通過ColJ填寫空白單元格。如果行中的單元格B-J爲空,則突出顯示colA中的單元格
我想改變ColA中單元格的背景顏色,當沒有數據輸入ColB時通過ColJ,但我沒有看到這樣做的方法。
我在Google Drive電子表格中包含一個簡單的電子表格,其中包含colA中的一個名稱列表。 ColB通過ColJ填寫空白單元格。如果行中的單元格B-J爲空,則突出顯示colA中的單元格
我想改變ColA中單元格的背景顏色,當沒有數據輸入ColB時通過ColJ,但我沒有看到這樣做的方法。
你會認爲條件格式會提供這種功能,但它不允許你引用其他單元。 (與Excel不同)
這是一個腳本,可以完成這項工作。 (如果你是新來的谷歌Apps腳本,閱讀this introduction。)
/**
* The onEdit() function, when defined, is automatically invoked whenever the
* spreadsheet is edited. (Not every change is an "edit".)
*
* If all of the "fill in the blanks" columns are empty, set the
* background color of the name column in that row.
*/
function onEdit(event) {
var row = event.range.getRow();
var sheet = event.range.getSheet();
var cellA = sheet.getRange(row,1);
// Get the range of cells B-J that make up the "fill in the blanks" range...
var fillInTheBlanks = sheet.getRange(row, 2, 1, 9)
.getValues()[0] // ... get values in 0-th row
.join(''); // ... and join into one string
// Check that string - if it is empty, the range was blank,
// and we should set the background color to, say, yellow.
if (fillInTheBlanks.length == 0) {
cellA.setBackground("yellow");
}
// On the other hand, if the string was NOT blank, there is something
// in the "fill in the blanks" range, so we will clear the background.
else {
cellA.setBackground("white");
}
}
/**
* The onOpen() function, when defined, is automatically invoked whenever the
* spreadsheet is opened.
*
* Iterates through all rows in spreadsheet, faking onEdit triggers, as if
* each name has been edited.
*/
function onOpen() {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var lastRow = sheet.getLastRow();
for (var row=1; row <= lastRow; row++) {
onEdit({range:sheet.getRange('A'+row)});
}
};
從ColumnA清除格式,選擇ColumnA和格式,條件格式...,單元格格式如果...... 自定義公式爲和:
=and(A1<>"",counta(B1:J1)=0)
然後選擇所選擇的填充和完成。