Private Sub Worksheet_Change(ByVal Target As Range)
Dim r As Long, c2 As String, c3 As String, data(), result(1 To 8, 1 To 1)
If Intersect(Target, Range("C2:C3")) Is Nothing Then Exit Sub
Application.EnableEvents = False
Me.Range("C7:C" & Me.Cells(Rows.Count, "A").End(xlUp).Row + 1).ClearContents
c2 = LCase(Me.Range("C2").Value)
c3 = LCase(Me.Range("C3").Value)
With ThisWorkbook.Worksheets("BAN DAU")
data = .Range("B7:L" & .Cells(Rows.Count, "B").End(xlUp).Row + 1).Value
End With
For r = 1 To UBound(data) - 1
If LCase(data(r, 1)) = c2 And LCase(data(r, 3)) = c3 Then
result(1, 1) = result(1, 1) & ";" & data(r, 4)
result(2, 1) = result(2, 1) & ";" & data(r, 5)
result(3, 1) = result(3, 1) + data(r, 6)
result(4, 1) = result(4, 1) & ";" & data(r, 7)
result(5, 1) = result(5, 1) & ";" & data(r, 8)
result(6, 1) = result(6, 1) + data(r, 9)
result(7, 1) = result(7, 1) + data(r, 10)
result(8, 1) = result(8, 1) & ";" & data(r, 11)
End If
Next r
If Len(result(1, 1)) Then
result(1, 1) = Mid(result(1, 1), 2)
result(2, 1) = Mid(result(2, 1), 2)
result(4, 1) = Mid(result(4, 1), 2)
result(5, 1) = Mid(result(5, 1), 2)
result(8, 1) = Mid(result(8, 1), 2)
Range("C7:C14").Value = result
End If
Application.EnableEvents = True
End Sub