3

如果某个值在is中,我正在尝试将一行从 toSheet1移动。例如:Sheet2Sheet1true

如果 B12=8/12/2012 in ,则将第 12 行从toSheet1复制到第 15 行(这将是一个命名范围)下添加一个新行,然后从中删除原始第 12 行。Sheet1Sheet2Sheet1

这可能吗?

4

1 回答 1

1

希望这会成功...

function copyRowtoDiffSheet(){
var ss = SpreadsheetApp.getActiveSpreadsheet();

 var sheet1 = ss.getSheetByName('Sheet1');
 var sheet2 = ss.getSheetByName('Sheet2');

 var cell = sheet1.getRange("B12").getCell(1, 1);//Get the B12 cell from sheet1
 var rowtoInsert = "15"; //Enter in which row you want to insert in sheet2

 if(cell.getValue() == "compareString") //compare cell.getValue() =="8/12/2012" 
 {

  sheet2.insertRows(rowtoInsert); //Insert a empty row in sheet2 at R15, It will be doing insert before operation. Successive rows will be moved below.
  var range2 = sheet2.getRange(rowtoInsert ,1,1,sheet1.getLastColumn()); // Select sheet2 row15 as a range
  sheet1.getRange(cell.getRow(),1, 1, sheet1.getLastColumn()).copyTo(range2); // copy the selected sheet1 range into sheet2 range
  sheet1.deleteRow(cell.getRow()); //delete the R15 in sheet1
 }
}
于 2014-08-28T14:01:47.343 回答