I have a Google Form that saves results to a Columns A:F of a googlesheet (called googlesheet1 in this example). I then need to import some of the data from the googlesheet1 to a second sheet (Columns C, D and F from googlesheet1 should go to columns A:C in googlesheet2). Data is manually entered into columns D:M of googlesheet2 and should be copied back to googlesheet1 (into columns I:R) with the row order preserved throughout the entire process.
I have all of this working with a series of =IMPORTRANGE formulas - but it's slow and causing lag. Is there a way to do this using a series of Google Apps scripts on the forms/sheets?
CodePudding user response:
A way to move data from one spreadsheet to another
function lfunko() {
const sss = SpreadsheetApp.getActive();
const dss = SpreadsheetApp.openById(gobj.globals.testsourceid);
const ssh = sss.getSheetByName("Sheet0");
const sshsr = 2;//row where data starts
const ssher = 20;//row where data ends
const sshsc = 2;//column where data starts
const sshec = 8;//column where data ends
const svs = ssh.getRange(sshsr,sshsc,ssher - sshsr 1, sshec - sshsc 1).getValues();
const dsh = dss.getSheetByName("Sheet0");
const dshsr = 4;//row where data starts in dsh
const dshsc = 4;//column where data start in dsh
dsh.getRange(dshsr,dshsc,svs.length,svs[0].length).setValues(svs)
}
ssh:
| A | B | C | D | E | F | G | H | I | J |
|---|---|---|---|---|---|---|---|---|---|
| COL1 | COL2 | COL3 | COL4 | COL5 | COL6 | COL7 | COL8 | COL9 | COL10 |
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
dsh:
| A | B | C | D | E | F | G | H | I | J |
|---|---|---|---|---|---|---|---|---|---|
| 2 | 3 | 4 | 5 | 6 | 7 | 8 | |||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 | |||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 | |||
| 6 | 7 | 8 | 9 | 10 | 11 | 12 | |||
| 7 | 8 | 9 | 10 | 11 | 12 | 13 | |||
| 8 | 9 | 10 | 11 | 12 | 13 | 14 | |||
| 9 | 10 | 11 | 12 | 13 | 14 | 15 | |||
| 10 | 11 | 12 | 13 | 14 | 15 | 16 | |||
| 11 | 12 | 13 | 14 | 15 | 16 | 17 | |||
| 12 | 13 | 14 | 15 | 16 | 17 | 18 | |||
| 13 | 14 | 15 | 16 | 17 | 18 | 19 | |||
| 14 | 15 | 16 | 17 | 18 | 19 | 20 | |||
| 15 | 16 | 17 | 18 | 19 | 20 | 21 | |||
| 16 | 17 | 18 | 19 | 20 | 21 | 22 | |||
| 17 | 18 | 19 | 20 | 21 | 22 | 23 | |||
| 18 | 19 | 20 | 21 | 22 | 23 | 24 | |||
| 19 | 20 | 21 | 22 | 23 | 24 | 25 | |||
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
