[英]copy rows that contains certain value and paste it to another sheet
I am trying to create a sheet that has a database mastersheet and 8 different locations.我正在尝试创建一个具有数据库主表和 8 个不同位置的工作表。
so everytime I submit a form to the database, I want my code to read the HUB location of the submitted form.所以每次我向数据库提交表单时,我都希望我的代码能够读取提交表单的 HUB 位置。 and copy that details of the submitted form to relevant sheet.
并将所提交表格的详细信息复制到相关表格。 this is what I have so far.
这就是我到目前为止所拥有的。
basically it will be easier if I describe the flow:基本上,如果我描述流程会更容易:
I hope this makes sense?我希望这是有道理的?
from what I can understand you want the answer to the form submitted to the main sheet then once the answer is submitted you what it to be sent to the relevant sheet据我所知,您想要提交给主表格的表格的答案,然后一旦提交答案,您将发送给相关表格的内容
for that i would create a form submit that places the answer to the sheet为此,我将创建一个表单提交,将答案放在工作表中
const SOURCE_FORM_ID = link; // Change according to your needs
{
const form = FormApp.openById(SOURCE_FORM_ID);
ScriptApp.newTrigger("onFormSubmitTrigger")
.forForm(form)
.onFormSubmit()
.create();
}
function onFormSubmitTrigger(e) {
const targetSpreadsheet = SpreadsheetApp.openById("insert sheet id");
const targetSheet = targetSpreadsheet.getSheetByName("C");
if (targetSheet.getLastRow() === 0) { // Add headers if they don't exist yet
const itemTitles = e.source.getItems().map(item => item.getTitle()); // Get item titles
itemTitles.unshift("Timestamp"); // Append "Timestamp" to the sheet (if desired)
targetSheet.appendRow(itemTitles); // Append form item titles to the sheet
}
const itemResponses = e.response.getItemResponses();
const responses = itemResponses.map(itemResponse => itemResponse.getResponse()); // Get user responses
responses.unshift(new Date()); // Add today's date to the responses (if desired)
targetSheet.appendRow(responses.map(e => Array.isArray(e) ? e.join(",") : e)); // Append responses to the sheet
}
the code above will create a trigger that is linked to your form that will submit the answer to a particular sheet上面的代码将创建一个链接到您的表单的触发器,该触发器将向特定工作表提交答案
after that a on edit or manually triggered code that moves it to the relevant sheet之后,将其移动到相关工作表的编辑或手动触发代码
var ss = SpreadsheetApp.getActiveSpreadsheet();
var seet = ss.getSheetByName('TC'); //source sheet
var testrange = seet.getRange('J:J'); //range to check
var testvalue = (testrange.getValues());
var csh = ss.getSheetByName('C'); //destination sheet
var data = [];
var j =[];
//Condition check in H:H; If true copy the same row to data array
for (i=0; i<testvalue.length;i++) {
if ( testvalue[i] == 'SENT') {
data.push.apply(data,seet.getRange(i+1,1,1,25).getValues());
//Copy matched ROW numbers to j
j.push(i);
}
}
//Copy data array to destination sheet
csh.getRange(csh.getLastRow()+1,1,data.length,data[0].length).setValues(data);
//Delete matched rows in the source sheet
for (i=0;i<j.length;i++){
var k = j[i]+1;
sheet.deleteRow(k);
//Alter j to account for deleted rows
if (!(i == j.length-1)) {
j[i+1] = j[i+1]-i-1;
}
the code above is what I use to move one row to another sheet with slight bit on modification you can get it to move it to the destination sheet while leaving it in the master sheet if you set up the form submit to send the form data to the master上面的代码是我用来将一行移动到另一张表并稍作修改的代码,如果您设置表单提交以将表单数据发送到大师
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.