如果是VBA,这将很容易。但事实并非如此, 我想用谷歌电子表格制作脚本我想做的是:
范围是动态的。 Sheet1 A7:I(i)
其中i是来自sheet1的最后一行(或者如果您愿意,第7行 - 来自sheet1的行,没有区别)
此范围必须粘贴为sheet2的下一个空行
然后我需要从sheet1删除行7-i
VBA代码可能是这样的:
Dim LastRow_Sheet1 As Long
LastRow_Sheet1 = Sheet1.Cells(Sheet1.Rows.Count, "A").End(xlUp).Row
Dim LastRow_Sheet2 As Long
LastRow_Sheet2 = Sheet2.Cells(Sheet2.Rows.Count, "A").End(xlUp).Row + 1
Dim Rng As Range
With Sheet1
Set Rng = .Range(.Cells(7, 1), .Cells(LastRow_Sheet1, 9))
End With
Rng.Copy
Sheet2.Cells(LastRow_Sheet2, 1).PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Sheet1.Rows("7:" & LastRow_Sheet1).Delete Shift:=xlUp
答案 0 :(得分:0)
我认为这就是你想要的。对不起,我忘了将其更改为专栏。我在Sheet2中任意选择了column1。
function copyFromSheet1ToSheet2()
{
var ss=SpreadsheetApp.getActive();
var sh1=ss.getSheetByName('Sheet1');
var sh2=ss.getSheetByName('Sheet2');
var rg1=sh1.getRange(7,1,sh1.getLastRow()-6,9);
var vA1=rg1.getValues();
var A=[];
for(var i=0;i<vA1.length;i++)
{
for(var j=0;j<vA1[i].length;j++)
{
A.push([vA1[i][j]]);
}
}
var rg2=sh2.getRange('A:A');
var vA2=rg2.getValues();
for(var i=0;i<vA2.length;i++)
{
if(!vA2[i][0])
{
var nextRowInColumn1=i+1;
var org=sh2.getRange(nextRowInColumn1,1,A.length,1);
org.setValues(A);
break;
}
}
for(var i=0;i<vA1.length;i++)
{
sh1.deleteRow(6 + vA1.length - i);
}
}