回答編集履歴
1
回答を追記しました。
answer
CHANGED
@@ -13,4 +13,26 @@
|
|
13
13
|
```
|
14
14
|
|
15
15
|
### 参考
|
16
|
-
- [getRange(row, column, numRows, numColumns)](https://developers.google.com/apps-script/reference/spreadsheet/sheet#getrangerow-column-numrows-numcolumns)
|
16
|
+
- [getRange(row, column, numRows, numColumns)](https://developers.google.com/apps-script/reference/spreadsheet/sheet#getrangerow-column-numrows-numcolumns)
|
17
|
+
|
18
|
+
## 追記
|
19
|
+
コメントにありました「コピー先のA列にはすでに値が入っており、B列の最終行とA列の最終行は異なり、B列の最終行の次の行に値をコピーしたい」との要望に対する修正案は次の通りです。ご確認ください。ご質問にあるスクリプトを書きのように修正し、動作をご確認ください。
|
20
|
+
|
21
|
+
### From
|
22
|
+
```javascript
|
23
|
+
var targetRow = sheet_copyTo.getLastRow()+1;
|
24
|
+
sheet_copyTo.getRange('B'+targetRow+':D'+targetRow).setValues(copyValue);
|
25
|
+
```
|
26
|
+
|
27
|
+
### To
|
28
|
+
```javascript
|
29
|
+
var targetColumnB = sheet_copyTo.getRange("B1:B" + sheet_copyTo.getLastRow()).getValues();
|
30
|
+
var targetRow = 0;
|
31
|
+
for (targetRow = targetColumnB.length - 1; targetRow >= 0; targetRow--) {
|
32
|
+
if (targetColumnB[targetRow][0]) {
|
33
|
+
targetRow += 2;
|
34
|
+
break;
|
35
|
+
}
|
36
|
+
}
|
37
|
+
sheet_copyTo.getRange(targetRow, 2, copyValue.length, copyValue[0].length).setValues(copyValue);
|
38
|
+
```
|