Excelで家計簿ソフトを作ってみよう

Step 14 先週の支出を合計する


収入と同様に支出を合計します。
支出は14種類あるので、合計する配列も14個用意しておきます。


Homeに戻る > Excelでアプリケーションソフト2 > 家計簿ソフト

実行画面

支出金額を集計するソフト


実行VBAコード

Private Sub ExSyukei(stdt As Date, endt As Date, lstr As Long, lenr As Long)
    Dim i As Long
    Dim j As Long
    Dim lin(7) As Long
    Dim sin(7) As String
    Dim lout(14) As Long
    Dim sout(14) As String
    
    For i = lstr To lenr
        '------ 収入 -------
        '給与
        If Cells(i, 4) = Sheets("日々の収入・支出入力").CommandButton1.Caption And Cells(i, 5) <> "" Then
            lin(0) = lin(0) + Cells(i, 5)
        '賞与
        ElseIf Cells(i, 4) = Sheets("日々の収入・支出入力").CommandButton2.Caption And Cells(i, 5) <> "" Then
            lin(1) = lin(1) + Cells(i, 5)
        'パート
        ElseIf Cells(i, 4) = Sheets("日々の収入・支出入力").CommandButton3.Caption And Cells(i, 5) <> "" Then
            lin(2) = lin(2) + Cells(i, 5)
        'アルバイト
        ElseIf Cells(i, 4) = Sheets("日々の収入・支出入力").CommandButton4.Caption And Cells(i, 5) <> "" Then
            lin(3) = lin(3) + Cells(i, 5)
        '年金
        ElseIf Cells(i, 4) = Sheets("日々の収入・支出入力").CommandButton5.Caption And Cells(i, 5) <> "" Then
            lin(4) = lin(4) + Cells(i, 5)
        '雑収入
        ElseIf Cells(i, 4) = Sheets("日々の収入・支出入力").CommandButton6.Caption And Cells(i, 5) <> "" Then
            lin(5) = lin(5) + Cells(i, 5)
        'その他
        ElseIf Cells(i, 4) = Sheets("日々の収入・支出入力").CommandButton7.Caption And Cells(i, 5) <> "" Then
            lin(6) = lin(6) + Cells(i, 5)
        '該当なし
        ElseIf Cells(i, 4) <> "" And Cells(i, 5) <> "" Then
            lin(7) = lin(7) + Cells(i, 5)
        End If
    
        '------ 支出 -------
        '食費
        If Cells(i, 4) = Sheets("日々の収入・支出入力").CommandButton8.Caption And Cells(i, 6) <> "" Then
            lout(0) = lout(0) + Cells(i, 6)
        '住居
        ElseIf Cells(i, 4) = Sheets("日々の収入・支出入力").CommandButton9.Caption And Cells(i, 6) <> "" Then
            lout(1) = lout(1) + Cells(i, 6)
        '電気
        ElseIf Cells(i, 4) = Sheets("日々の収入・支出入力").CommandButton10.Caption And Cells(i, 6) <> "" Then
            lout(2) = lout(2) + Cells(i, 6)
        'ガス
        ElseIf Cells(i, 4) = Sheets("日々の収入・支出入力").CommandButton11.Caption And Cells(i, 6) <> "" Then
            lout(3) = lout(3) + Cells(i, 6)
        '水道
        ElseIf Cells(i, 4) = Sheets("日々の収入・支出入力").CommandButton12.Caption And Cells(i, 6) <> "" Then
            lout(4) = lout(4) + Cells(i, 6)
        '電話
        ElseIf Cells(i, 4) = Sheets("日々の収入・支出入力").CommandButton13.Caption And Cells(i, 6) <> "" Then
            lout(5) = lout(5) + Cells(i, 6)
        '被服
        ElseIf Cells(i, 4) = Sheets("日々の収入・支出入力").CommandButton14.Caption And Cells(i, 6) <> "" Then
            lout(6) = lout(6) + Cells(i, 6)
        '交通
        ElseIf Cells(i, 4) = Sheets("日々の収入・支出入力").CommandButton15.Caption And Cells(i, 6) <> "" Then
            lout(7) = lout(7) + Cells(i, 6)
        '医療
        ElseIf Cells(i, 4) = Sheets("日々の収入・支出入力").CommandButton16.Caption And Cells(i, 6) <> "" Then
            lout(8) = lout(8) + Cells(i, 6)
        '教育
        ElseIf Cells(i, 4) = Sheets("日々の収入・支出入力").CommandButton17.Caption And Cells(i, 6) <> "" Then
            lout(9) = lout(9) + Cells(i, 6)
        '保険
        ElseIf Cells(i, 4) = Sheets("日々の収入・支出入力").CommandButton18.Caption And Cells(i, 6) <> "" Then
            lout(10) = lout(10) + Cells(i, 6)
        '税金
        ElseIf Cells(i, 4) = Sheets("日々の収入・支出入力").CommandButton19.Caption And Cells(i, 6) <> "" Then
            lout(11) = lout(11) + Cells(i, 6)
        '交際
        ElseIf Cells(i, 4) = Sheets("日々の収入・支出入力").CommandButton20.Caption And Cells(i, 6) <> "" Then
            lout(12) = lout(12) + Cells(i, 6)
        'その他
        ElseIf Cells(i, 4) = Sheets("日々の収入・支出入力").CommandButton21.Caption And Cells(i, 6) <> "" Then
            lout(13) = lout(13) + Cells(i, 6)
        '該当なし
        ElseIf Cells(i, 4) <> "" And Cells(i, 6) <> "" Then
            lout(14) = lout(14) + Cells(i, 6)
        End If
    Next
    
End Sub



Homeに戻る > Excelでアプリケーションソフト2 > 家計簿ソフト

■■■
このサイトの内容を利用して発生した、いかなる問題にも一切責任は負いませんのでご了承下さい
■■■
当ホームページに掲載されているあらゆる内容の無許可転載・転用を禁止します


Copyright (c) Excel-Excel ! All rights reserved