回答編集履歴

9

修正

2022/06/21 11:50

投稿

退会済みユーザー
test CHANGED
@@ -27,9 +27,9 @@
27
27
  ##### コピー元データの各列を詰めてコピー先に貼り付けたい場合
28
28
  ```js
29
29
  function myFunction3() {
30
- const sourceSheet = SpreadsheetApp.getActive().getSheetByName('全体');
30
+ const sourceSheet = SpreadsheetApp.getActive().getSheetByName('ページ');
31
31
  const sourceRangeList= sourceSheet.getRangeList(['A2:B', 'E2:E', 'H2:H', 'K2:K']);
32
- const destinationSheet = SpreadsheetApp.getActive().getSheetByName('ページ');
32
+ const destinationSheet = SpreadsheetApp.getActive().getSheetByName('全体');
33
33
  let startColumn = 1;
34
34
  const startRow = 2;
35
35
  sourceRangeList.getRanges().forEach(range => {

8

 

2022/06/19 01:20

投稿

退会済みユーザー
test CHANGED
@@ -13,10 +13,10 @@
13
13
  ```js
14
14
  function myFunction2() {
15
15
  const sourceSheet = SpreadsheetApp.getActive().getSheetByName('ページ');
16
- const sourceRanges = sourceSheet.getRangeList(['A2:B', 'E2:E', 'H2:H', 'K2:K']);
16
+ const sourceRangeList = sourceSheet.getRangeList(['A2:B', 'E2:E', 'H2:H', 'K2:K']);
17
17
  const destinationSheet = SpreadsheetApp.getActive().getSheetByName('全体');
18
18
 
19
- sourceRanges.getRanges().forEach(range => {
19
+ sourceRangeList.getRanges().forEach(range => {
20
20
  range.copyTo(destinationSheet.getRange(range.getA1Notation()), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
21
21
  });
22
22
  }
@@ -28,11 +28,11 @@
28
28
  ```js
29
29
  function myFunction3() {
30
30
  const sourceSheet = SpreadsheetApp.getActive().getSheetByName('全体');
31
- const sourceRanges = sourceSheet.getRangeList(['A2:B', 'E2:E', 'H2:H', 'K2:K']);
31
+ const sourceRangeList= sourceSheet.getRangeList(['A2:B', 'E2:E', 'H2:H', 'K2:K']);
32
32
  const destinationSheet = SpreadsheetApp.getActive().getSheetByName('ページ');
33
33
  let startColumn = 1;
34
34
  const startRow = 2;
35
- sourceRanges.getRanges().forEach(range => {
35
+ sourceRangeList.getRanges().forEach(range => {
36
36
  const destinationRange = destinationSheet.getRange(startRow, startColumn, range.getNumRows(), range.getNumColumns());
37
37
  range.copyTo(destinationRange, SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
38
38
  startColumn += range.getNumColumns();

7

 

2022/06/19 01:19

投稿

退会済みユーザー
test CHANGED
@@ -12,9 +12,9 @@
12
12
 
13
13
  ```js
14
14
  function myFunction2() {
15
- var sourceSheet = SpreadsheetApp.getActive().getSheetByName('ページ');
15
+ const sourceSheet = SpreadsheetApp.getActive().getSheetByName('ページ');
16
- var sourceRanges = sourceSheet.getRangeList(['A2:B', 'E2:E', 'H2:H', 'K2:K']);
16
+ const sourceRanges = sourceSheet.getRangeList(['A2:B', 'E2:E', 'H2:H', 'K2:K']);
17
- var destinationSheet = SpreadsheetApp.getActive().getSheetByName('全体');
17
+ const destinationSheet = SpreadsheetApp.getActive().getSheetByName('全体');
18
18
 
19
19
  sourceRanges.getRanges().forEach(range => {
20
20
  range.copyTo(destinationSheet.getRange(range.getA1Notation()), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
@@ -27,9 +27,9 @@
27
27
  ##### コピー元データの各列を詰めてコピー先に貼り付けたい場合
28
28
  ```js
29
29
  function myFunction3() {
30
- var sourceSheet = SpreadsheetApp.getActive().getSheetByName('全体');
30
+ const sourceSheet = SpreadsheetApp.getActive().getSheetByName('全体');
31
- var sourceRanges = sourceSheet.getRangeList(['A2:B', 'E2:E', 'H2:H', 'K2:K']);
31
+ const sourceRanges = sourceSheet.getRangeList(['A2:B', 'E2:E', 'H2:H', 'K2:K']);
32
- var destinationSheet = SpreadsheetApp.getActive().getSheetByName('ページ');
32
+ const destinationSheet = SpreadsheetApp.getActive().getSheetByName('ページ');
33
33
  let startColumn = 1;
34
34
  const startRow = 2;
35
35
  sourceRanges.getRanges().forEach(range => {

6

修正

2022/06/19 01:18

投稿

退会済みユーザー
test CHANGED
@@ -33,7 +33,7 @@
33
33
  let startColumn = 1;
34
34
  const startRow = 2;
35
35
  sourceRanges.getRanges().forEach(range => {
36
- const destinationRange = destinationSheet.getRange(startRow, startColumn, range.getNumColumns(), range.getNumRows());
36
+ const destinationRange = destinationSheet.getRange(startRow, startColumn, range.getNumRows(), range.getNumColumns());
37
37
  range.copyTo(destinationRange, SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
38
38
  startColumn += range.getNumColumns();
39
39
  });

5

 

2022/06/19 01:16

投稿

退会済みユーザー
test CHANGED
@@ -24,7 +24,7 @@
24
24
 
25
25
  ----
26
26
 
27
- # コピー元データの各列を詰めてコピー先に貼り付けたい場合
27
+ ##### コピー元データの各列を詰めてコピー先に貼り付けたい場合
28
28
  ```js
29
29
  function myFunction3() {
30
30
  var sourceSheet = SpreadsheetApp.getActive().getSheetByName('全体');

4

追記

2022/06/19 01:16

投稿

退会済みユーザー
test CHANGED
@@ -22,3 +22,20 @@
22
22
  }
23
23
  ```
24
24
 
25
+ ----
26
+
27
+ # コピー元データの各列を詰めてコピー先に貼り付けたい場合
28
+ ```js
29
+ function myFunction3() {
30
+ var sourceSheet = SpreadsheetApp.getActive().getSheetByName('全体');
31
+ var sourceRanges = sourceSheet.getRangeList(['A2:B', 'E2:E', 'H2:H', 'K2:K']);
32
+ var destinationSheet = SpreadsheetApp.getActive().getSheetByName('ページ');
33
+ let startColumn = 1;
34
+ const startRow = 2;
35
+ sourceRanges.getRanges().forEach(range => {
36
+ const destinationRange = destinationSheet.getRange(startRow, startColumn, range.getNumColumns(), range.getNumRows());
37
+ range.copyTo(destinationRange, SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
38
+ startColumn += range.getNumColumns();
39
+ });
40
+ }
41
+ ```

3

 

2022/06/18 11:40

投稿

退会済みユーザー
test CHANGED
@@ -1,7 +1,7 @@
1
1
  > Exception: Invalid argument: a1Notations というエラー
2
2
 
3
3
  getRangeList('ページ!'['A2:A', 'E2:E', 'H2:H', 'K2:K']) という指定方法はできません。
4
- これだと「ページ!」という文字列に対して「'A2:A', 'E2:E', 'H2:H', 'K2:K'」というプロパティを指定しているので、undefined と評価され、引数として不正(invalid)になります。
4
+ これだと「ページ!」という文字列に対して「'A2:A', 'E2:E', 'H2:H', 'K2:K'」というプロパティを指定しているので、undefined と評価され、引数として無効(invalid)になります。
5
5
   
6
6
  そもそもgetRangeList(['ページ!A2:A', 'ページ!E2:E', 'ページ!H2:H', 'ページ!K2:K']);
7
7
  という指定方法もできません。

2

 

2022/06/18 11:40

投稿

退会済みユーザー
test CHANGED
@@ -1,7 +1,7 @@
1
1
  > Exception: Invalid argument: a1Notations というエラー
2
2
 
3
3
  getRangeList('ページ!'['A2:A', 'E2:E', 'H2:H', 'K2:K']) という指定方法はできません。
4
- これだと「ページ!」という文字列に対して「'A2:A', 'E2:E', 'H2:H', 'K2:K'」というプロパティを指定しているので、undefined と評価され、引数として不正す。
4
+ これだと「ページ!」という文字列に対して「'A2:A', 'E2:E', 'H2:H', 'K2:K'」というプロパティを指定しているので、undefined と評価され、引数として不正(invalid)になります。
5
5
   
6
6
  そもそもgetRangeList(['ページ!A2:A', 'ページ!E2:E', 'ページ!H2:H', 'ページ!K2:K']);
7
7
  という指定方法もできません。

1

 

2022/06/18 07:59

投稿

退会済みユーザー
test CHANGED
@@ -12,9 +12,9 @@
12
12
 
13
13
  ```js
14
14
  function myFunction2() {
15
- var sourceSheet = SpreadsheetApp.getActive().getSheetByName('全体');
15
+ var sourceSheet = SpreadsheetApp.getActive().getSheetByName('ページ');
16
16
  var sourceRanges = sourceSheet.getRangeList(['A2:B', 'E2:E', 'H2:H', 'K2:K']);
17
- var destinationSheet = SpreadsheetApp.getActive().getSheetByName('ページ');
17
+ var destinationSheet = SpreadsheetApp.getActive().getSheetByName('全体');
18
18
 
19
19
  sourceRanges.getRanges().forEach(range => {
20
20
  range.copyTo(destinationSheet.getRange(range.getA1Notation()), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);