简体   繁体   English

将行移动到另一个工作表并清除内容/ ArrayFormula

[英]Moving Row to another sheet and clear content/ ArrayFormula

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例如第 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.我有 4 张。 Sheet1a and Sheet1b have vlookup formulas between them. Sheet1aSheet1b之间有 vlookup 公式。 Sheet2a and Sheet2b will also have the same Vlookup formula between them. 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)))

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 .由于它是一个 ArrayFormula,只要设置了Sheet2aSheet2b ,就应该只在特定单元格中的内容移动之前清除它,因为它作为文本值传输并破坏Sheet2aSheet2b中的公式。

Adding the ability to clear some cells in rows 7,13,24,25,34添加清除第 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);
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM