[英]Google App Scripts - How to clear multiple cells' content based on another cell?
Im trying to check a column's values for the words "No Show" and if a cell has that value I need it to delete some cells on the same row so for example if column I5 has "No Show" as its value I need to clear cells B5,C5,D5,F5,G5.我试图检查列的值是否包含“No Show”一词,如果一个单元格具有该值,我需要它删除同一行上的一些单元格,例如,如果 I5 列的值是“No Show”,我需要清除单元格 B5、C5、D5、F5、G5。 I tried to write something but its not working and im relatively new to this.
我试图写一些东西,但它不起作用,我对此相对较新。 Thanks for the help
谢谢您的帮助
I believe your goal as follows.我相信你的目标如下。
No Show
for each row.No Show
”时,您要清除“B”、“C”、“D”、“F”和“G”列的单元格值。 In this case, I would like to propose to use TextFinder and the method of clearContent()
of Class RangeList.在这种情况下,我想建议使用 TextFinder 和 Class RangeList 的
clearContent()
方法。 The sample script is as follows.示例脚本如下。
Please copy and paste the following script to the script editor of Google Spreadsheet and set the sheet name you want to use, and run the function myFunction
at the script editor.请将以下脚本复制并粘贴到 Google 电子表格的脚本编辑器中并设置您要使用的工作表名称,然后在脚本编辑器中运行 function
myFunction
。
function myFunction() {
const sheetName = "Sheet1"; // Please set the sheet name.
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
const ranges = sheet
.getRange("I1:I" + sheet.getLastRow())
.createTextFinder("No Show")
.matchCase(true)
.findAll()
.flatMap(r => {
const row = r.getRow();
return ["B", "C", "D", "F", "G"].map(e => e + row);
});
if (ranges.length > 0) sheet.getRangeList(ranges).clearContent();
}
No Show
for each row.No Show
”时,“B”、“C”、“D”、“F”和“G”列的单元格值将被清除。No Show
, when you want to check No Show
, no show
and so on, please remove .matchCase(true)
.No Show
的搜索值,当要勾选No Show
、 no show
等时,请去掉.matchCase(true)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.