英文:
Clear row of cells within a range after another cell is edited - Google Sheets
问题
以下代码将在更改E4时清除F4到P4单元格。如何使此代码适用于除E4之外的其他单元格?即如果更改E5,则清除F5到P5,如果更改E6,则清除F6到P6,以此类推。谢谢!
function onEdit(e){
var editedCell = e.range.getA1Notation();
if (editedCell.charAt(0) === 'E') {
var rowNumber = parseInt(editedCell.substring(1));
e.source.getActiveSheet().getRange("F" + rowNumber + ":P" + rowNumber).clearContent();
}
}
英文:
The below code will clear cells F4 to P4 once E4 is changed. How can I make this code apply to more than just E4? i.e. If E5 is changed then clear F5 to P5, if E6 is changed then clear F6 to P6, etc. Thank you!
function onEdit(e){
if(e.range.getA1Notation() != "E4") return;
e.source.getActiveSheet().getRange("F4:p4").clearContent()
}
答案1
得分: 0
你可以尝试使用行数和列数。在第一个IF语句中,我已经检查了列是否不是第5列(也就是E列),或者行是否小于4(如果需要修改E3、E2或E1,请进行更改);然后从第6列开始清除接下来的11列:
function onEdit(e){
if(e.range.getColumn() != 5 || e.range.getRow() < 4) return;
e.source.getActiveSheet().getRange(6,e.range.getRow(),11,1).clearContent()
}
英文:
You can try working with numbers of rows and columns. In the first IF I've checked if the column is not number 5 (meaning, column E) or row is less than 4 (please, change it if you need to modify E3, E2 or E1); and then make it clear from the 6th columns the next 11 columns:
function onEdit(e){
if(e.range.getColumn() != 5 || e.range.getRow() < 4) return;
e.source.getActiveSheet().getRange(6,e.range.getRow(),11,1).clearContent()
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论