且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

根据时间自动将值仅粘贴到另一列

更新时间:2022-02-27 22:11:51

你如何调用这个脚本?作为电子表格或脚本编辑器中的公式?
如果您将它用作公式,则可以直接读取范围。
如果您是通过脚本编辑器调用它的,则可以对脚本进行一些小改动,使其可以在大于单元格的范围内工作。请参阅下面的代码

How are you invoking this script ? As a formula in the spreadsheet or from the script editor ? If you're using it as a formula, you can read the range directly. If you're invoking it from the script editor, you can make small changes to your script to make it work across a range larger than a cell. See the code below

function moveValuesOnly() {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var range= sheet.getRange("B4:R20");
var currentValue = range.getValues(); // Change 20 to whatever you want
var COL_B = 0;  // relative to col B 
var COL_H = 6;
var COL_R = 16; 

for(var i = 0 ; i < currentValue.length ; i++){
if (currentValue[i][0] == (15)) {

// Copy value in H4, H5 etc to R4, R5 etc. 
currentValue[i][COL_R] = currentValue[i][COL_H];
}
range.setValues(currentValue);
}

我没有测试过,但如果发现任何小错误,修复它:)

I haven't tested it but if you find any minor errors feel free to fix it:)