回答編集履歴

1

追記

2021/06/16 09:49

投稿

jinoji
jinoji

スコア4592

test CHANGED
@@ -111,3 +111,97 @@
111
111
  MsgBox ("完了")
112
112
 
113
113
  ```
114
+
115
+
116
+
117
+ ---
118
+
119
+ <追記>
120
+
121
+ 消費税を合算しない場合のことを忘れていました。
122
+
123
+
124
+
125
+ ```VBA
126
+
127
+
128
+
129
+ '(略)
130
+
131
+ Dim dictA As Object '金額
132
+
133
+ Set dictA = CreateObject("Scripting.Dictionary") ' 連想配列の定義
134
+
135
+ Dim dictZ As Object '消費税
136
+
137
+ Set dictZ = CreateObject("Scripting.Dictionary") ' 連想配列の定義
138
+
139
+
140
+
141
+ For row1 = 2 To maxrow1
142
+
143
+ k(0) = sh1.Cells(row1, 2)
144
+
145
+ k(1) = dictT(sh1.Cells(row1, 1))
146
+
147
+ k(2) = IIf(sh1.Cells(row1, 3) = kuni, kuni, kuni & "以外")
148
+
149
+
150
+
151
+ key = Join(k, "|")
152
+
153
+
154
+
155
+ If Not sh1.Cells(row1, 2) Like "*税*" Then
156
+
157
+ dictA(key) = dictA(key) + sh1.Cells(row1, 4)
158
+
159
+ Else
160
+
161
+ dictZ(key) = dictZ(key) + sh1.Cells(row1, 4)
162
+
163
+ End If
164
+
165
+ Next
166
+
167
+
168
+
169
+ Dim sh2 As Worksheet
170
+
171
+ Set sh2 = Worksheets("Sheet2")
172
+
173
+ sh2.Rows("2:" & Rows.Count).ClearContents 'Sheet2の2行目以降をクリア
174
+
175
+
176
+
177
+ Dim row2 As Long
178
+
179
+ row2 = 2
180
+
181
+ Dim keys As Variant
182
+
183
+
184
+
185
+ For Each key In dictAmount
186
+
187
+ keys = Split(key, "|")
188
+
189
+ sh2.Cells(row2, "A").Value = keys(0) 'タイトル
190
+
191
+ sh2.Cells(row2, "B").Value = keys(1) '取引区別
192
+
193
+ sh2.Cells(row2, "C").Value = dictA(key) + dictZ(key) '金額+消費税
194
+
195
+ sh2.Cells(row2, "D").Value = keys(2) '購入国
196
+
197
+ ' sh2.Cells(row2, "E").Value = dictA(key) '金額
198
+
199
+ row2 = row2 + 1
200
+
201
+ Next
202
+
203
+ MsgBox ("完了")
204
+
205
+
206
+
207
+ ```