Something like:
Option Explicit
'==========================================Specify Variables====================================================='
Sub SortByCategory()
Dim ws As Worksheet
Dim lRow As Long
Dim i As Integer 'Row counter
Dim SumGroceries As Integer 'Category counter for sum
Dim SumLiving As Integer
Dim SumRestaurantBar As Integer
Dim SumAthletics As Integer
Dim Cat As String 'Category string for sorting
Dim month_count
'========================================== Specify Worksheet===================================================='
Set ws = ThisWorkbook.Sheets("2013") 'Need to change the worksheet name as years are added
With ws
lRow = .Range("A" & .Rows.Count).End(xlUp).Row
End With
'==========================================Sum Totals Per Category==============================================='
For month_count = 1 To 12
For i = 2 To lRow
Cat = ws.Range("B" & i)
'Input each of the catgories listed in the "Categories" tab below (ensure the SumCategory is also added to variable list As Integer)
If Cat = "Groceries" And month_count = Month(Range("A" & i)) Then SumGroceries = SumGroceries + ws.Range("C" & i)
If Cat = "Living" And month_count = Month(Range("A" & i)) Then SumLiving = SumLiving + ws.Range("C" & i)
If Cat = "Restaurant/Bar" And month_count = Month(Range("A" & i)) Then SumRestaurantBar = SumRestaurantBar + ws.Range("C" & i)
If Cat = "Athletics" And month_count = Month(Range("A" & i)) Then SumAthletics = SumAthletics + ws.Range("C" & i)
Next i
MsgBox "Month: " & month_count & " Groceries " & SumGroceries & "Living " & SumLiving & "Rest/Bar " & SumRestaurantBar & "Athletics " & SumAthletics
Next
'==========================================Message box to test coding=============================================='
MsgBox "Groceries " & SumGroceries & "Living " & SumLiving & "Rest/Bar " & SumRestaurantBar & "Athletics " & SumAthletics
End Sub
Assuming your dates are actually dates and not just text strings.
Bookmarks