Capture.JPG
Option Explicit
Option Compare Text
Sub GetTotal()
Dim iRow As Long
Dim Total As Double
Dim TheYear As Variant, TheMonth As Variant
Dim Theitem As String
With ActiveSheet
' get your values from the linked cells.
TheYear = Trim(.Range("E1").Value)
TheMonth = Trim(.Range("F1").Value)
Theitem = Trim(.Range("G1").Value)
For iRow = 2 To .Cells(1, 1).CurrentRegion.Rows.Count
If CStr(.Cells(iRow, 1).Value) = TheYear Or TheYear = "all" Then
If .Cells(iRow, 2).Value = TheMonth Or TheMonth = "all" Then
If .Cells(iRow, 3).Value = Theitem Or Theitem = "all" Then
Total = Total + .Cells(iRow, 4).Value
End If
End If
End If
Next iRow
.Cells(1, 1).End(xlDown).Offset(1, 3).Value = Total ' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
End With
End Sub