Home > database >  Google script to append multiple rows - select columns
Google script to append multiple rows - select columns

Time:08-11

How can I append multiple rows from source sheet to destination sheet; select columns like A,C,H ? source sheet columns A-Z, with multiple rows. destination sheet - append rows from source sheet - select columns A, C and H only. Thank you

CodePudding user response:

Transfer Data from one sheet to another selecting only columns A,C and H

function xferdata() {
  const ss = SpreadsheetApp.getActive();
  const ssh = ss.getSheetByName("Sheet0");
  const dsh = ss.getSheetByName("Sheet1");
  const vs = ssh.getRange(2,1,ssh.getLastRow() - 1, 8).getValues();
  let o = vs.map(([a,,c,,,,,h]) => [a,c,h]);
  //Logger.log(JSON.stringify(o));
  dsh.getRange(dsh.getLastRow()   1,1,o.length,o[0].length).setValues(o);
}

Sheet0:

COL1 COL2 COL3 COL4 COL5 COL6 COL7 COL8
1 2 3 4 5 6 7 8
2 3 4 5 6 7 8 9
3 4 5 6 7 8 9 10
4 5 6 7 8 9 10 11
5 6 7 8 9 10 11 12
6 7 8 9 10 11 12 13
7 8 9 10 11 12 13 14
8 9 10 11 12 13 14 15
9 10 11 12 13 14 15 16
10 11 12 13 14 15 16 17
11 12 13 14 15 16 17 18
12 13 14 15 16 17 18 19
13 14 15 16 17 18 19 20
14 15 16 17 18 19 20 21
15 16 17 18 19 20 21 22
16 17 18 19 20 21 22 23
17 18 19 20 21 22 23 24
18 19 20 21 22 23 24 25
19 20 21 22 23 24 25 26
20 21 22 23 24 25 26 27

Sheet1:

A B C
1 3 8
2 4 9
3 5 10
4 6 11
5 7 12
6 8 13
7 9 14
8 10 15
9 11 16
10 12 17
11 13 18
12 14 19
13 15 20
14 16 21
15 17 22
16 18 23
17 19 24
18 20 25
19 21 26
20 22 27
  • Related