(2)2重ループ繰り返しの使い方
(a)各月の計算
合計計算(6行目)・消費税計算(7行目)・税込計算(8行目)を1月から3月までiを使って繰り返す。
繰り返し前
'1月の計算
Cells(6, 2) = Cells(3, 2) + Cells(4, 2) + Cells(5, 2)
Cells(7, 2) = Cells(6, 2) * 消費税
Cells(8, 2) = Cells(6, 2) + Cells(7, 2)
i = 1
'2月の計算
Cells(6, 2 + i) = Cells(3, 2 + i) + Cells(4, 2 + i) + Cells(5, 2 + i)
Cells(7, 2 + i) = Cells(6, 2 + i) * 消費税
Cells(8, 2 + i) = Cells(6, 2 + i) + Cells(7, 2 + i)
i = i + 1
'3月の計算
Cells(6, 2 + i) = Cells(3, 2 + i) + Cells(4, 2 + i) + Cells(5, 2 + i)
Cells(7, 2 + i) = Cells(6, 2 + i) * 消費税
Cells(8, 2 + i) = Cells(6, 2 + i) + Cells(7, 2 + i)
i = i + 1
繰り返し後
'各月の計算
For i = 0 To 2
Cells(6, 2 + i) = Cells(3, 2 + i) + Cells(4, 2 + i) + Cells(5, 2 + i)
Cells(7, 2 + i) = Cells(6, 2 + i) * 消費税
Cells(8, 2 + i) = Cells(6, 2 + i) + Cells(7, 2 + i)
Next
(b)大阪・名古屋・東京の計算
合計計算(5列目)・消費税計算(6列目)・税込計算(7列目)を大阪・名古屋・東京までiを使って繰り返す。
繰り返し前
'合計の計算(i=3)
Cells(3, 2 + i) = Cells(3, 2 + i - 3) + Cells(3, 2 + i - 2) + Cells(3, 2 + i - 1)
Cells(4, 2 + i) = Cells(4, 2 + i - 3) + Cells(4, 2 + i - 2) + Cells(4, 2 + i - 1)
Cells(5, 2 + i) = Cells(5, 2 + i - 3) + Cells(5, 2 + i - 2) + Cells(5, 2 + i - 1)
Cells(6, 2 + i) = Cells(6, 2 + i - 3) + Cells(6, 2 + i - 2) + Cells(6, 2 + i - 1)
Cells(7, 2 + i) = Cells(7, 2 + i - 3) + Cells(7, 2 + i - 2) + Cells(7, 2 + i - 1)
Cells(8, 2 + i) = Cells(8, 2 + i - 3) + Cells(8, 2 + i - 2) + Cells(8, 2 + i - 1)
繰り返し後
For i = 3 To 8
Cells(i, 5) = Cells(i, 2) + Cells(i, 3) + Cells(i, 4)
Next
(c)地区の消費税総合計の計算
繰り返し前
'消費税の計算
Cells(3, 2 + i) = Cells(3, 2 + i - 1) * 消費税
Cells(4, 2 + i) = Cells(4, 2 + i - 1) * 消費税
Cells(5, 2 + i) = Cells(5, 2 + i - 1) * 消費税
Cells(6, 2 + i) = Cells(6, 2 + i - 1) * 消費税
i = i + 1
'総合計の計算
Cells(3, 2 + i) = Cells(3, 2 + i - 2) + Cells(3, 2 + i - 1)
Cells(4, 2 + i) = Cells(4, 2 + i - 2) + Cells(4, 2 + i - 1)
Cells(5, 2 + i) = Cells(5, 2 + i - 2) + Cells(5, 2 + i - 1)
Cells(6, 2 + i) = Cells(6, 2 + i - 2) + Cells(6, 2 + i - 1)
繰り返し後
For i = 3 To 6
Cells(i, 6) = Cells(i, 5) * 消費税
Cells(i, 7) = Cells(i, 5) + Cells(i, 6)
Next