Option Explicit
Function TongHopCong(Rng0 As Range, Optional Coluong As Byte = 1)
Const NCo As String = "XPDT": Const N0Co As String = "KR"
Dim Tru As Integer, jJ As Byte
Dim Format_ As String, GPE As String
Dim Rng As Range, sRng As Range, Cls As Range, WF As Object, Clls As Range
Set WF = Application.WorksheetFunction
Select Case Coluong
Case Is < 3
GPE = Choose(Coluong, NCo, N0Co)
For jJ = 1 To Choose(Coluong, 4, 2)
TongHopCong = TongHopCong + WF.CountIf(Rng0, Mid(GPE, jJ, 1))
Next jJ
Case 3
Set Rng = [E9].Resize(, 31): Format_ = Rng.NumberFormat
Rng.NumberFormat = "MM/dd/yyyy"
1 'Tính Them Giò Ngày Thuòng:'
TongHopCong = WF.Sum(Rng0)
For Each Cls In Rng
For Each Clls In Range("NgLe")
If Cls.Value = Clls.Value Then
2 'Tính Them Giò Ngày Le:'
TongHopCong = TongHopCong + 2 * Cells(Rng0.Row, Cls.Column).Value
Exit For
End If
Next Clls
3 'Tính Them Giò Ngày CN :'
If Weekday(Cls.Value) = 1 Then _
TongHopCong = TongHopCong + Cells(Rng0.Row, Cls.Column).Value
Next Cls
Rng.NumberFormat = Format_
End Select
End Function