Option Explicit
Sub SoSanhDuLieu()
Dim lRow As Long, cRow As Long, dRow As Long
Dim jW As Long, jZ As Long, jJ As Long
Dim Rng As Range, RngC As Range: Dim iJ As Integer
lRow = [c65432].End(xlUp).Row: Range("B38:R321").Clear
Range("F2:O2").Copy Destination:=Range("F38")
Application.ScreenUpdating = False
For jW = 18 To 23
cRow = Range(Chr(64 + jW) & 36).End(xlUp).Row
If cRow = 1 Then GoTo 17
For jJ = 3 To lRow
For jZ = 2 To cRow
If Cells(jJ, 3) = Cells(jZ, jW) Then
If Rng Is Nothing And RngC Is Nothing Then
Set Rng = Cells(jZ - 1, jW)
Set RngC = Cells(jJ, 3).Resize(1, 13)
Else
Set Rng = Union(Rng, Cells(jZ, jW))
Set RngC = Union(RngC, Cells(jJ, 3).Resize(1, 13))
End If
End If
Next jZ
Next jJ
dRow = [F65432].End(xlUp).Row + 1
If dRow > 39 Then dRow = dRow + 1:
Rng.Copy Destination:=Range("B" & dRow)
RngC.Copy Destination:=Range("C" & dRow)
Set Rng = Nothing: Set RngC = Nothing
17 Next jW
lRow = [c65432].End(xlUp).Row + 1: dRow = 39
For jW = 39 To lRow
If Cells(jW, 4) = "" Then
cRow = jW - 1
Cells(jW, 4).Formula = "=SUM(D" & dRow & ":D" & cRow & ")"
Range("D" & jW).AutoFill Destination:=Range("D" & jW & _
":O" & jW), Type:=xlFillDefault
dRow = jW + 1
End If
Next jW
End Sub