You have prepared col G & H, Criteria 1 & 2.
Do you want to keep it remain as it is, or is it fine just the data that have month=N1?
This is to output the only data that have Month = N1
to a Sheet Module
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(0, 0) <> "N1" Then Exit Sub
Application.EnableEvents = False
test
Application.EnableEvents = True
End Sub
To a standard module
Sub test()
Dim a, i As Long, ii As Long, w, txt As String, myMonth As Long
myMonth = [n1].Value
a = Cells(1).CurrentRegion.Resize(, 4).Value
With CreateObject("Scripting.Dictionary")
.CompareMode = 1
For i = 2 To UBound(a, 1)
If a(i, 3) = myMonth Then
txt = Join(Array(a(i, 1), a(i, 2)), Chr(2))
If Not .exists(txt) Then
ReDim w(1 To 3)
For ii = 1 To 2
w(ii) = a(i, ii)
Next
Else
w = .Item(txt)
End If
w(3) = w(3) + a(i, 4)
.Item(txt) = w
End If
Next
a = Empty
If .Count Then a = Application.Index(.items, 0, 0)
End With
[g1:h1].CurrentRegion.Offset(1).ClearContents
[k1].CurrentRegion.Offset(1).ClearContents
If IsArray(a) Then
[g2:h2].Resize(UBound(a, 1)).Value = a
[k2].Resize(UBound(a, 1)).Value = Application.Index(a, 0, 3)
End If
End Sub
Bookmarks