質問編集履歴

1

画像の追加

2021/01/22 14:55

投稿

k_m_rad8sfttns
k_m_rad8sfttns

スコア1

test CHANGED
File without changes
test CHANGED
@@ -1,223 +1,223 @@
1
+ ##![イメージ説明](d63ea7d6d6ce6beaa904fc0c09b7465d.png)現したいこと
2
+
3
+ H列のデータを3つずつ平均して、U列のセルに書き込んで表を作りたいです。H列の最後の端数は、2つのデータの平均か1つのデータをそのままU列に書き込みたいです。
4
+
5
+
6
+
7
+ ####発生している問題・エラーメッセージ
8
+
9
+ H2からH16までは順調に処理してくれるのですが、そのあとH27とH28のセルを平均してしまい、そのあとになぜかH20からまた正常に処理を再開します。
10
+
11
+
12
+
13
+ ```
14
+
15
+ エラーメッセージは出ません
16
+
17
+ ```
18
+
19
+
20
+
1
21
  ### 前提・実現したいこと
2
22
 
23
+
24
+
25
+ ```VBA
26
+
27
+ Sub 表作成()
28
+
29
+
30
+
31
+ Dim i
32
+
3
- H列のデータを3つずつ平均して、U列のセルに書き込んで表を作りたいです。H列の最後の端数は、2つのデータの平均か1つのデータをそのままU列に書き込みたいです。
33
+ For i = 1 To 3
4
-
5
-
6
-
34
+
7
- ####発生している問題・エラーメッセージ
35
+ Sheets(i).Select
36
+
37
+
38
+
8
-
39
+ Range("T1").Value = "西進(6H)"
40
+
9
- H2からH16までは順調に処理してくれるのですが、そのあとH27とH28のセルを平均してしまい、そのあとになぜかH20からまた正常に処理を再開します。
41
+ Range("U1").Value = "経度平均(12H)"
42
+
43
+ Range("V1").Value = "西進(12H)"
44
+
45
+ Range("W1").Value = "経度平均(24H)"
46
+
47
+ Range("X1").Value = "西進(24H)"
48
+
49
+
50
+
51
+ Columns("U").ColumnWidth = 12
52
+
53
+ Columns("V").ColumnWidth = 8.5
54
+
55
+ Columns("W").ColumnWidth = 12
56
+
57
+ Columns("X").ColumnWidth = 8.5
58
+
59
+
60
+
61
+ Dim t
62
+
63
+ For t = 3 To 100
64
+
65
+ If Cells(t, 8) = "" Then
66
+
67
+ Exit For
68
+
69
+ End If
70
+
71
+
72
+
73
+ Cells(t, 20).Value = "=IF(H" & CStr(t) & "-H" & CStr(t - 1) & "<0,""0"",""1"")"
74
+
75
+
76
+
77
+ Next t
78
+
79
+
80
+
81
+ Dim u
82
+
83
+ For u = 2 To 100
84
+
85
+ If Cells(3 * u - 4, 8) = "" Then
86
+
87
+ Exit For
88
+
89
+
90
+
91
+ ElseIf Cells(3 * u - 3, 8) = "" Then
92
+
93
+ Cells(u, 21) = Cells(3 * u - 4, 8)
94
+
95
+ Exit For
96
+
97
+
98
+
99
+ ElseIf Cells(3 * u - 2, 8) = "" Then
100
+
101
+ Cells(u, 21).Value = "=AVERAGE(H" & CStr(3 * u - 4) & ":H" & CStr(3 * u - 3) & ")"
102
+
103
+ Exit For
104
+
105
+ End If
106
+
107
+
108
+
109
+ Cells(u, 21).Value = "=AVERAGE(H" & CStr(3 * u - 4) & ":H" & CStr(3 * u - 2) & ")"
110
+
111
+
112
+
113
+ Next u
114
+
115
+
116
+
117
+ Dim v
118
+
119
+ For v = 3 To 100
120
+
121
+ If Cells(v, 21) = "" Then
122
+
123
+ Exit For
124
+
125
+ End If
126
+
127
+
128
+
129
+ Cells(v, 22).Value = "=IF(U" & CStr(v) & "-U" & CStr(v - 1) & "<0,""0"",""1"")"
130
+
131
+
132
+
133
+ Next
134
+
135
+
136
+
137
+ Dim w
138
+
139
+ For w = 2 To 100
140
+
141
+ If Cells(5 * w - 8, 8) = "" Then
142
+
143
+ Exit For
144
+
145
+
146
+
147
+ ElseIf Cells(5 * w - 7, 8) = "" Then
148
+
149
+ Cells(w, 21) = Cells(5 * w - 8, 8)
150
+
151
+ Exit For
152
+
153
+
154
+
155
+ ElseIf Cells(5 * w - 6, 8) = "" Then
156
+
157
+ Cells(w, 21).Value = "=AVERAGE(H" & CStr(5 * w - 8) & ":H" & CStr(5 * w - 7) & ")"
158
+
159
+ Exit For
160
+
161
+
162
+
163
+ ElseIf Cells(5 * w - 5, 8) = "" Then
164
+
165
+ Cells(w, 21).Value = "=AVERAGE(H" & CStr(5 * w - 8) & ":H" & CStr(5 * w - 6) & ")"
166
+
167
+ Exit For
168
+
169
+
170
+
171
+ ElseIf Cells(5 * w - 4, 8) = "" Then
172
+
173
+ Cells(w, 21).Value = "=AVERAGE(H" & CStr(5 * w - 8) & ":H" & CStr(5 * w - 5) & ")"
174
+
175
+ Exit For
176
+
177
+ End If
178
+
179
+
180
+
181
+ Cells(w, 23).Value = "=AVERAGE(H" & CStr(5 * w - 8) & ":H" & CStr(5 * w - 4) & ")"
182
+
183
+
184
+
185
+ Next w
186
+
187
+
188
+
189
+ Dim x
190
+
191
+ For x = 3 To 100
192
+
193
+ If Cells(x, 23) = "" Then
194
+
195
+ Exit For
196
+
197
+ End If
198
+
199
+
200
+
201
+ Cells(x, 23).Value = "=IF(W" & CStr(x) & "-W" & CStr(x - 1) & "<0,""0"",""1"")"
202
+
203
+
204
+
205
+ Next x
206
+
207
+
208
+
209
+
210
+
211
+ Next i
212
+
213
+
214
+
215
+ End Sub
10
216
 
11
217
 
12
218
 
13
219
  ```
14
220
 
15
- エラーメッセージは出ません
16
-
17
- ```
18
-
19
-
20
-
21
- ### 前提・実現したいこと
22
-
23
-
24
-
25
- ```VBA
26
-
27
- Sub 表作成()
28
-
29
-
30
-
31
- Dim i
32
-
33
- For i = 1 To 3
34
-
35
- Sheets(i).Select
36
-
37
-
38
-
39
- Range("T1").Value = "西進(6H)"
40
-
41
- Range("U1").Value = "経度平均(12H)"
42
-
43
- Range("V1").Value = "西進(12H)"
44
-
45
- Range("W1").Value = "経度平均(24H)"
46
-
47
- Range("X1").Value = "西進(24H)"
48
-
49
-
50
-
51
- Columns("U").ColumnWidth = 12
52
-
53
- Columns("V").ColumnWidth = 8.5
54
-
55
- Columns("W").ColumnWidth = 12
56
-
57
- Columns("X").ColumnWidth = 8.5
58
-
59
-
60
-
61
- Dim t
62
-
63
- For t = 3 To 100
64
-
65
- If Cells(t, 8) = "" Then
66
-
67
- Exit For
68
-
69
- End If
70
-
71
-
72
-
73
- Cells(t, 20).Value = "=IF(H" & CStr(t) & "-H" & CStr(t - 1) & "<0,""0"",""1"")"
74
-
75
-
76
-
77
- Next t
78
-
79
-
80
-
81
- Dim u
82
-
83
- For u = 2 To 100
84
-
85
- If Cells(3 * u - 4, 8) = "" Then
86
-
87
- Exit For
88
-
89
-
90
-
91
- ElseIf Cells(3 * u - 3, 8) = "" Then
92
-
93
- Cells(u, 21) = Cells(3 * u - 4, 8)
94
-
95
- Exit For
96
-
97
-
98
-
99
- ElseIf Cells(3 * u - 2, 8) = "" Then
100
-
101
- Cells(u, 21).Value = "=AVERAGE(H" & CStr(3 * u - 4) & ":H" & CStr(3 * u - 3) & ")"
102
-
103
- Exit For
104
-
105
- End If
106
-
107
-
108
-
109
- Cells(u, 21).Value = "=AVERAGE(H" & CStr(3 * u - 4) & ":H" & CStr(3 * u - 2) & ")"
110
-
111
-
112
-
113
- Next u
114
-
115
-
116
-
117
- Dim v
118
-
119
- For v = 3 To 100
120
-
121
- If Cells(v, 21) = "" Then
122
-
123
- Exit For
124
-
125
- End If
126
-
127
-
128
-
129
- Cells(v, 22).Value = "=IF(U" & CStr(v) & "-U" & CStr(v - 1) & "<0,""0"",""1"")"
130
-
131
-
132
-
133
- Next
134
-
135
-
136
-
137
- Dim w
138
-
139
- For w = 2 To 100
140
-
141
- If Cells(5 * w - 8, 8) = "" Then
142
-
143
- Exit For
144
-
145
-
146
-
147
- ElseIf Cells(5 * w - 7, 8) = "" Then
148
-
149
- Cells(w, 21) = Cells(5 * w - 8, 8)
150
-
151
- Exit For
152
-
153
-
154
-
155
- ElseIf Cells(5 * w - 6, 8) = "" Then
156
-
157
- Cells(w, 21).Value = "=AVERAGE(H" & CStr(5 * w - 8) & ":H" & CStr(5 * w - 7) & ")"
158
-
159
- Exit For
160
-
161
-
162
-
163
- ElseIf Cells(5 * w - 5, 8) = "" Then
164
-
165
- Cells(w, 21).Value = "=AVERAGE(H" & CStr(5 * w - 8) & ":H" & CStr(5 * w - 6) & ")"
166
-
167
- Exit For
168
-
169
-
170
-
171
- ElseIf Cells(5 * w - 4, 8) = "" Then
172
-
173
- Cells(w, 21).Value = "=AVERAGE(H" & CStr(5 * w - 8) & ":H" & CStr(5 * w - 5) & ")"
174
-
175
- Exit For
176
-
177
- End If
178
-
179
-
180
-
181
- Cells(w, 23).Value = "=AVERAGE(H" & CStr(5 * w - 8) & ":H" & CStr(5 * w - 4) & ")"
182
-
183
-
184
-
185
- Next w
186
-
187
-
188
-
189
- Dim x
190
-
191
- For x = 3 To 100
192
-
193
- If Cells(x, 23) = "" Then
194
-
195
- Exit For
196
-
197
- End If
198
-
199
-
200
-
201
- Cells(x, 23).Value = "=IF(W" & CStr(x) & "-W" & CStr(x - 1) & "<0,""0"",""1"")"
202
-
203
-
204
-
205
- Next x
206
-
207
-
208
-
209
-
210
-
211
- Next i
212
-
213
-
214
-
215
- End Sub
216
-
217
-
218
-
219
- ```
220
-
221
221
 
222
222
 
223
223
  ### 試したこと
@@ -233,3 +233,5 @@
233
233
 
234
234
 
235
235
  ### 補足情報(FW/ツールのバージョンなど)
236
+
237
+ ![イメージ説明](489f4a421ca287ab9e2612d0b27eb122.png)