VBA講座 レッスン2 合計計算
マイナスの合計とプラスの合計を別々に集計する

- ●コマンドボタンを押すと下のコードが実行され集計が表示されます。
Private Sub CommandButton1_Click() Dim rowEnd As Integer Dim colEnd As Integer Dim i, n As Integer rowEnd = 6 colEnd = 7 Row = 3 col = 2 For i = 3 To rowEnd minus = 0: plus = 0 For n = 2 To colEnd If Cells(Row, col) < 0 Then minus = minus + Cells(Row, col) Else plus = plus + Cells(Row, col) End If col = col + 1 Next n minusT = minusT + minus plusT = plusT + plus Cells(i, colEnd + 1) = minus Cells(i, colEnd + 2) = plus Row = Row + 1 col = 2 Next i Cells(rowEnd + 1, colEnd + 1) = minusT Cells(rowEnd + 1, colEnd + 2) = plusT End Sub
- ■ここで問題です。
- ■赤で囲った部分の縦の集計を自分の力で出力できるようにプログラムを変更してみてください。
- ■がんばってね( ^)o(^ )
