Sub GPE()
Dim sArr(), Res(), S As Variant
Dim Dic As Object, sh As Worksheet
Dim sRow As Long, i As Long, ik As Long, j As Byte, jCol As Byte
Set Dic = CreateObject("scripting.dictionary")
With Sheets("K12")
i = .Range("c" & Rows.Count).End(xlUp).Row
If i < 5 Then MsgBox ("khong co Hoc Sinh"): Exit Sub
j = Range("AAA4").End(xlToLeft).Column
If j < 7 Then MsgBox ("khong co Mon Hoc"): Exit Sub
sArr = .Range("C5:C" & i).Value
sRow = UBound(sArr, 1)
For i = 1 To sRow
If Len(sArr(i, 1)) > 0 Then Dic.Item(sArr(i, 1)) = i
Next i
sArr = .Range("G4", .Cells(4, j)).Value
For j = 1 To UBound(sArr, 2)
If Len(sArr(1, j)) > 0 Then Dic.Item(UCase(sArr(1, j))) = j
Next j
ReDim Res(1 To sRow, 1 To UBound(sArr, 2))
End With
For Each sh In ThisWorkbook.Sheets
If sh.Name <> "K12" Then
S = Split(" " & Application.Trim(sh.Range("C3").Value), " ")
jCol = Dic.Item(UCase(S(UBound(S))))
If jCol > 0 Then
i = sh.Range("B" & Rows.Count).End(xlUp).Row
If i > 4 Then
sArr = sh.Range("B5:E" & i).Value
For i = 1 To UBound(sArr, 1)
ik = Dic.Item(sArr(i, 1))
If ik > 0 Then Res(ik, jCol) = sArr(i, 4)
Next i
End If
End If
End If
Next
Sheets("K12").Range("G5").Resize(sRow, UBound(Res, 2)) = Res
End Sub