将K列中具有给定值的一张纸上的每行数据复制到另一张纸上 [英] Copy every row of Data from one sheet that has a given value in column K to another sheet

查看:69
本文介绍了将K列中具有给定值的一张纸上的每行数据复制到另一张纸上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个Google Spreadsheet,它将使用一个脚本将K列中的完成过去30天中的每一行数据复制到另一张表。



表单是指每个选项卡。
Source选项卡是Arley目标选项卡当前是ArleysSandbox
每行有11列,A-K。整行应结转。
工作表中总行数将随着时间的推移而增加。
每次运行脚本时,我都希望它先清除ArleysSandbox上的所有现有数据。
K栏表示过去30天内完成是一个公式。
我最终希望从多张工作表中拉出并编译。

我以旧论坛的帖子为出发点,但由于缺乏知识而陷入困境。 http://productforums.google.com/forum/#!msg / apps-script / FNGzVkEqZh4 / x8WCYtjvpI8J 在此先感谢您的任何建议。 解决方案

不要冒犯,但我认为这个论坛不是一个可以免费获得应用程序的市场,它应该给那些试图自己获得结果的人提供答案。



,这是一个'skeletton',应该把你放在正确的轨道上,我试图用评论解释发生了什么。 (没测试过,可能需要调试)

$ p $ function copy2(){
var ss = SpreadsheetApp。 getActiveSpreadsheet();
var sh = SpreadsheetApp.setActiveSheet(ss.getSheets()[0]);选择电子表格中的第一个工作表
var data = sh.getDataRange()。getValues(); //数据是二维数组,index0 = col A
//所以列k是索引10
var target = new Array(); //这是一个新数组来收集数据
for(n = 0; n taget.push(data [n ]); //复制整行
}
}
if(target.length> 0){//如果有东西需要复制
var sh2 = SpreadsheetApp.setActiveSheet (ss.getSheets()[1]); //第二张电子表格
sh2.getRange(1,1,target.length,target [0] .length).setValues(); //将选定的值粘贴到一个批次中的2秒工作表中
}
}


I'm working on a Google Spreadsheet the will use a Script to copy every row of Data from one sheet that has "Done In The Past 30 Days" in column K to another sheet.

By "sheet" I mean every tab. Source tab is "Arley" destination tab is currently "ArleysSandbox" Every row has ll columns, A-K. The entire row should be carried over. The number of total rows in the sheet will increase over time. Every time I run the Script, I want it to clear all existing data on "ArleysSandbox" first. Column K, where it says "Done In Past 30 Days" is a formula. I will eventually want to pull from multiple sheets and compile on the Sandbox sheet.

I was using a post from the old forum as a starting point but got stuck due to my lack of knowledge. http://productforums.google.com/forum/#!msg/apps-script/FNGzVkEqZh4/x8WCYtjvpI8J Thanks in advance for any suggestions.

解决方案

don't be offended but I think this forum is not a market place where you can get apps for free, it is supposed to bring answers to poeple that try to get results by themselves.

That said, here is a 'skeletton' that should put you on the right tracks, I tried to explain with the comments what was happening. (didn't test it, maybe it needs debugging)

function copy2(){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh = SpreadsheetApp.setActiveSheet(ss.getSheets()[0]); selects the first sheet in your spreadsheet
  var data=sh.getDataRange().getValues();// data is a 2D array, index0 = col A
  // so column k is index 10
  var target=new Array();// this is a new array to collect data
  for(n=0;n<data.length;++n){ // iterate in the array, row by row
    if (data[n][10]=="Done In The Past 30 Days"){ ;// if condition is true copy the whole row to target
    taget.push(data[n]);// copy the whole row
    }
    }
    if(target.length>0){// if there is something to copy
  var sh2=SpreadsheetApp.setActiveSheet(ss.getSheets()[1]); //second sheet of your spreadsheet
  sh2.getRange(1,1,target.length,target[0].length).setValues();// paste the selected values in the 2cond sheet in one batch write
  }
} 

这篇关于将K列中具有给定值的一张纸上的每行数据复制到另一张纸上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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