Option Explicit
Sub Thong_Ke()
Dim Ws As Worksheet
Dim i&, R&, C%, Names$, K&, Times$, Col&, j&
Dim Dic As Object
Dim DL(), KQ()
Set Dic = CreateObject("Scripting.dictionary")
Application.ScreenUpdating = False
'-------------------------------------------------------------------------------------------------------
With Sheet1
C = .Range("XFD3").End(xlToLeft).Column - 1
DL = .Range("B3", .Range("B" & Rows.Count).End(xlUp)).Resize(, C).Value
R = UBound(DL)
ReDim KQ(1 To R - 1, 1 To C - 2)
For i = 2 To UBound(DL)
Names = Trim(DL(i, 1))
If Not Dic.exists(Names) Then Dic.Add Names, i - 1
Next
For i = 3 To UBound(DL, 2)
Times = Trim(DL(1, i))
If Not Dic.exists(Times) Then Dic.Add Times, i - 2
Next
End With
For Each Ws In ActiveWorkbook.Worksheets
If Ws.Name <> "tonghop" Then
With Ws
C = .Range("XFD3").End(xlToLeft).Column - 1
If C > 1 Then
DL = .Range("B3", .Range("B" & Rows.Count).End(xlUp)).Resize(, C).Value
For i = 2 To UBound(DL)
Names = Trim(DL(i, 1))
If Dic.exists(Names) Then
For j = 2 To C
Times = Trim(DL(1, j))
If Dic.exists(Times) Then
Col = Dic.Item(Times)
K = Dic.Item(Names)
KQ(K, Col) = KQ(K, Col) + DL(i, j)
End If
Next
End If
Next
End If
End With
End If
Next
Set Dic = Nothing
Sheet1.Range("D4").Resize(UBound(KQ), UBound(KQ, 2)).ClearContents
Sheet1.Range("D4").Resize(UBound(KQ), UBound(KQ, 2)) = KQ
Sheet1.Range("A3").Resize(UBound(DL), UBound(DL, 2) + 1).Borders.LineStyle = 1
Sheet1.Range("A3").Resize(UBound(KQ), UBound(KQ, 2)).Sort Key1:=Sheet1.Range("c3"), Order1:=xlDescending, Header:=xlYes
Application.ScreenUpdating = True
End Sub