根据时间自动将值仅粘贴到另一列 [英] Pasting values only to another column automatically based on time passed

查看:91
本文介绍了根据时间自动将值仅粘贴到另一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在设置一个Google文档来使用ImportXML来跟踪实时的网页数据,并且希望在特定的时间间隔后将这些数字复制到其他列。我正在跟踪输入的日期信息,然后每15天自动将此信息复制到多个帐户的另一列。这是我到目前为止正在处理第1行的代码,但是现在我已经为一个单元格工作,我希望单独为整个列执行此操作:

I am currently working on setting up a Google Doc to track live web data using ImportXML and want to copy those figures to other columns after specific time intervals. I am tracking the date info is entered and then for every 15 days automatically copying this info to another column for multiple accounts. Here is my code so far which is working on row 1, but now that I have it working for one cell I want to do this for the whole column individually:

function moveValuesOnly() {
var sheet = SpreadsheetApp.getActiveSpreadsheet()
var currentValue = sheet.getRange("B4").getValue();
if (currentValue == (15)) {


var ss = SpreadsheetApp.getActiveSpreadsheet();
var source = ss.getRange("H4");
var copyRange = ss.getRange("H4");
var l = ss.getDataRange().getValues().length;
var pasteRange = ss.getRange("R4");
pasteRange.setValues(copyRange.getValues());
}}

var sheet = SpreadsheetApp.getActiveSpreadsheet()
var currentValue = sheet.getRange("B5").getValue();
if (currentValue == (30)) {


var ss = SpreadsheetApp.getActiveSpreadsheet();
var source = ss.getRange("H4");
var copyRange = ss.getRange("H4");
var l = ss.getDataRange().getValues().length;
var pasteRange = ss.getRange("T5");
pasteRange.setValues(copyRange.getValues());
}

有没有办法让它逐行评估,而不是一次全部评估?我猜测我不应该使用范围,但我不知道如何做到这一点。任何帮助将非常感谢!如果我可以澄清任何让我知道的。

Is there any way to have it evaluate line by line and not all at once? I am guessing I should not be using range, but I have no idea how else to do this. Any help will be very much appreciated!! If I can clarify anything let me know.

谢谢!

THANK YOU!

推荐答案

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

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:)

这篇关于根据时间自动将值仅粘贴到另一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆