如果Sheet1
中的某个值是Sheet2
,我试图将行从Sheet1
移到true
。例如:
如果Sheet1
中的B12 = 8/12/2012,则通过在第15行下添加一个新行(这将是一个命名范围)将第12行从Sheet1
复制到Sheet2
,然后从。
这可能吗?
最佳答案
希望这能解决...
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
}
}
关于google-apps-script - 有条件地将行从一张纸移动到另一张纸,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12047375/