Option Explicit
Function XepLoaiL5(Diem As Range, DanhGia As Range, _
Optional XepLoai As Boolean = True) As String
Dim Rng As Range
Set Rng = Union(Diem, DanhGia)
With Application.WorksheetFunction
If .CountA(Rng) < Rng.Count Then
XepLoaiL5 = ""
Else
If .CountIf(DanhGia, "B") > 0 Then
XepLoaiL5 = "Yeu"
ElseIf .CountIf(Diem, "TB") > 0 Then
XepLoaiL5 = "TB"
ElseIf .CountIf(Diem, "K") > 0 Then
XepLoaiL5 = "Kha"
ElseIf .CountIf(Diem, "G") = 4 Then
XepLoaiL5 = "Gioi"
Else
XepLoaiL5 = "Yeu"
End If
End If
End With
If Not XepLoai Then
If XepLoaiL5 = "Gioi" Then
XepLoaiL5 = "HS Gioi"
ElseIf XepLoaiL5 = "Kha" Then
XepLoaiL5 = "HS Tien Tien"
Else
XepLoaiL5 = ""
End If
End If
End Function