清除在编辑另一个单元格后范围内的行 – Google Sheets

huangapple go评论67阅读模式
英文:

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() &lt; 4) return;
  e.source.getActiveSheet().getRange(6,e.range.getRow(),11,1).clearContent()
}

huangapple
  • 本文由 发表于 2023年7月18日 05:48:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76708284.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定