将行移动到另一张纸并清除内容/ArrayFormula

发布于 2025-01-12 12:09:04 字数 1297 浏览 1 评论 0原文

短篇故事: 如何修改下面的脚本以清除该行中多个单元格中的内容?例如行 7,13,24,25,34

长话短说(如果有更好的解决方案):

我一直在使用此脚本根据值在工作表之间移动行,而不保留格式,以便下一张纸有自己的格式,并且条件格式不会堆积起来。

  function onEditComplete(e) {
 //e.source.toast('Entry');
 //Logger.log(JSON.stringify(e));
 const sh=e.range.getSheet();
 if(sh.getName()=="Sheet1a" && e.range.columnStart==5 && e.value=="Completed") {
  //e.source.toast('Conditional');
 var tsh=e.source.getSheetByName("Sheet2a");
 tsh.getRange(tsh.getLastRow()+1,1,1,sh.getLastColumn()).setValues(sh.getRange(e.range.rowStart,1,1,sh.getLastColumn()). 
getValues());
sh.deleteRow(e.range.rowStart);}
  }

我现在遇到的问题是我正在使用公式。 我有4张。 Sheet1aSheet1b 之间有 vlookup 公式。 Sheet2aSheet2b 之间也将具有相同的 Vlookup 公式。

=ArrayFormula(IFERROR(VLOOKUP(PARTS!$B1:$B,{PARTS!$B1:$B,PARTS!$AF1:$BD&","&PARTS!$AJ1:$AJ&","&PARTS!$AN1:$AN&","&PARTS!$AR1:$AR&","&PARTS!$AV1:$AV&","&PARTS!$AR1:$AR&","&PARTS!$AZ1:$AZ},2,0)))

由于它是一个 ArrayFormula,只要设置了 Sheet2aSheet2b,它就应该只需要在移动之前清除特定单元格中的内容,因为它作为文本传输值并打破 Sheet2aSheet2b 中的公式。

Short story:
How do I modify the script below to clear contents in multiple cells in the row? For example Rows 7,13,24,25,34

Long story (in case there is a better solution):

I have been using this script to move rows between sheets based on a value without carrying over the formatting so the next sheet has its own and the conditional formatting isn't stacking up.

  function onEditComplete(e) {
 //e.source.toast('Entry');
 //Logger.log(JSON.stringify(e));
 const sh=e.range.getSheet();
 if(sh.getName()=="Sheet1a" && e.range.columnStart==5 && e.value=="Completed") {
  //e.source.toast('Conditional');
 var tsh=e.source.getSheetByName("Sheet2a");
 tsh.getRange(tsh.getLastRow()+1,1,1,sh.getLastColumn()).setValues(sh.getRange(e.range.rowStart,1,1,sh.getLastColumn()). 
getValues());
sh.deleteRow(e.range.rowStart);}
  }

The problem I am encountering now is I am using Formulas.
I have 4 sheets. Sheet1a and Sheet1b have vlookup formulas between them. Sheet2a and Sheet2b will also have the same Vlookup formula between them.

=ArrayFormula(IFERROR(VLOOKUP(PARTS!$B1:$B,{PARTS!$B1:$B,PARTS!$AF1:$BD&","&PARTS!$AJ1:$AJ&","&PARTS!$AN1:$AN&","&PARTS!$AR1:$AR&","&PARTS!$AV1:$AV&","&PARTS!$AR1:$AR&","&PARTS!$AZ1:$AZ},2,0)))

Since it's an ArrayFormula, as long as Sheet2a and Sheet2b are set it should only be a matter of clearing the content in the specific cells before it moves over since it transfers as text value and breaks the formula in Sheet2a and Sheet2b.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葬シ愛 2025-01-19 12:09:04

添加清除第 7、13、24、25、34 行中某些单元格的功能

function onEdit(e) {
  e.source.toast('Entry');
  Logger.log(JSON.stringify(e));
  const sh = e.range.getSheet();
  if (sh.getName() == "Sheet0" && e.range.columnStart == 5 && e.value == "Completed") {
    e.source.toast('Conditional');
    let cols = [7, 13, 24, 25, 34];
    let row = sh.getRange(e.range.rowStart, 1, 1, sh.getLastColumn()).getValues().flat().map((e, i) => {
      if (~cols.indexOf(i + 1)) {
        return null;
      } else {
        return e;
      }
    })
    var tsh = e.source.getSheetByName("Sheet1");
    tsh.getRange(tsh.getLastRow() + 1, 1, 1, sh.getLastColumn()).setValues([row]);
    sh.deleteRow(e.range.rowStart);
  }
}

Adding the ability to clear some cells in rows 7,13,24,25,34

function onEdit(e) {
  e.source.toast('Entry');
  Logger.log(JSON.stringify(e));
  const sh = e.range.getSheet();
  if (sh.getName() == "Sheet0" && e.range.columnStart == 5 && e.value == "Completed") {
    e.source.toast('Conditional');
    let cols = [7, 13, 24, 25, 34];
    let row = sh.getRange(e.range.rowStart, 1, 1, sh.getLastColumn()).getValues().flat().map((e, i) => {
      if (~cols.indexOf(i + 1)) {
        return null;
      } else {
        return e;
      }
    })
    var tsh = e.source.getSheetByName("Sheet1");
    tsh.getRange(tsh.getLastRow() + 1, 1, 1, sh.getLastColumn()).setValues([row]);
    sh.deleteRow(e.range.rowStart);
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文