Option Explicit
Function TKCong(LookUpRange As Range, Optional Tuan As Range, _
Optional LoaiCong As String = "X") As Variant
Dim Clls As Range
For Each Clls In LookUpRange
With Clls
Select Case UCase$(LoaiCong)
Case "X"
If IsNumeric(.Value) And .Value <= 8 Then TKCong = TKCong + .Value
Case "N"
If IsNumeric(.Value) And .Value < 8 And .Value <> "" Then _
TKCong = TKCong + (8 - .Value)
Case "T", "TG"
If IsNumeric(.Value) And .Value > 8 Then TKCong = TKCong + .Value - 8
Case "C", "CN"
If Cells(Tuan.Cells(1, 1).Row, .Column).Value = "CN" Then _
TKCong = TKCong + .Value
Case "L"
If InStr(.Value, "L") And Len(.Value) > 1 Then _
TKCong = TKCong + CDbl(Mid(.Value, 2))
Case Else
End Select
End With
Next Clls
End Function