質問編集履歴

1

修正

2022/01/11 02:38

投稿

aRyo
aRyo

スコア23

test CHANGED
File without changes
test CHANGED
@@ -34,7 +34,7 @@
34
34
 
35
35
  function myFunction() {
36
36
 
37
- //1. 現在のスプレッドシートを取得
37
+ //1. 現在のスプレッドシートを取得
38
38
 
39
39
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
40
40
 
@@ -44,71 +44,79 @@
44
44
 
45
45
  const lastRow = sheet.getLastRow();
46
46
 
47
- var count_i = 0
47
+ var count = 0;
48
48
 
49
+ var count2 = 0;
49
50
 
51
+ for(var j = 0 ; j <= lastRow; ++j) {
50
52
 
51
- for(var j = 0 ; j <= 10; ++j) {
53
+ currentRow = 2
52
54
 
53
- for(var i = 2+count_i ; i <= lastRow; ++i) {
55
+ for(var i = currentRow ; i <= lastRow; ++i) {///////////////////////currentRowを、次の日にちに変更させたい
54
56
 
55
- var range_try = sheet.getRange(i, 1);
57
+ var range1 = sheet.getRange(i, 1);
56
58
 
57
- var range_try2 = sheet.getRange(i+1, 1);
59
+ var value1 = range1.getValue();
58
60
 
59
- var value1 = range_try.getValue;
61
+ var range2 = sheet.getRange(i+1, 1);
60
62
 
61
- var value2 = range_try2.getValue;
63
+ var value2 = range2.getValue();
62
64
 
63
-  console.log(value1);
65
+ //ログに出力
64
66
 
65
-  console.log(value2);
67
+ Logger.log(value1);
66
68
 
67
- console.log(i);
69
+ Logger.log(value2);
68
70
 
69
- if ( value1  !=  value2)
71
+ count++
70
72
 
73
+ if ( value1  !=  value2)
74
+
71
- break;
75
+ break;
72
76
 
73
77
  }
74
78
 
75
79
 
76
80
 
77
- /////////ここからそれぞれ同じ日にちごとに処理したい内容
78
-
79
- console.log(i);
80
-
81
- var date = sheet.getRange(i, 1, i+1, 5);
82
-
83
- var sheet2 = spreadsheet.getSheetByName('指示書(サンプル)');
84
-
85
- sheet2.copyTo(spreadsheet);
86
-
87
- var sheet3 = spreadsheet.getSheetByName('指示書(サンプル) のコピー');
88
-
89
-  sheet3.setName("指示書"+i);
90
81
 
91
82
 
83
+ count2++
92
84
 
93
- const range_to = sheet3.getRange("A5");
85
+ Logger.log("i:"+i);
94
86
 
95
- //アクティブなセルに貼付け
87
+ Logger.log("count:"+count);
96
88
 
89
+ Logger.log("count2:"+count2);
90
+
91
+ var date = sheet.getRange(i-count+1, 2, count, 5);
92
+
93
+ var sheet2 = spreadsheet.getSheetByName('指示書(サンプル)');
94
+
95
+ sheet2.copyTo(spreadsheet);
96
+
97
+ var sheet3 = spreadsheet.getSheetByName('指示書(サンプル) のコピー');
98
+
99
+ sheet3.setName("指示書"+count2);
100
+
101
+ const range_to = sheet3.getRange("A5");
102
+
103
+ //アクティブなセルに貼付け
104
+
97
- date.copyTo(range_to, {contentsOnly:true});
105
+ date.copyTo(range_to, {contentsOnly:true});
106
+
107
+
98
108
 
99
109
  var cell = sheet3.getRange("A2:F10");
100
110
 
101
111
  cell.setHorizontalAlignment("center");
102
112
 
103
- cell.setVerticalAlignment("middle")
113
+ cell.setVerticalAlignment("middle");
104
114
 
105
115
 
106
116
 
107
- count_i = i+1
108
117
 
109
- }
110
118
 
111
- }
119
+ }}
112
120
 
113
121
 
114
122