Option Explicit
Function Max3Ngay(Dau As Long, Optional Nhuan As Byte = 0)
Dim Tong As Double, jJ As Byte, Temp As Double
Dim SoNg As Byte, Ng As Byte, Thg As Byte, Dem As Byte
Dim WF As Object, Rng As Range, Cls As Range
Set WF = Application.WorksheetFunction
For jJ = 2 To 13
SoNg = Choose(jJ - 1, 31, 28 + Nhuan, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
Set Rng = Cells(Dau, jJ).Resize(SoNg).SpecialCells(xlCellTypeConstants, 1)
Dem = 0
For Each Cls In Rng
Dem = Dem + 1
If Dem < SoNg - 1 Then
If Cls.Offset(1).Value > 0 And Cls.Offset(2).Value > 0 And Cls.Value > 0 Then
Tong = WF.Sum(Cls.Resize(3))
If Tong > Temp Then
Temp = Tong: Ng = Cells(Cls.Row, "A").Value
Thg = jJ - 1
End If
End If
ElseIf Dem = SoNg - 1 Then
If Cls.Value > 0 And Cls.Offset(1).Value > 0 And Cells(Dau, jJ + 1).Value > 0 Then
Tong = WF.Sum(Union(Cls.Resize(2), Cells(Dau, jJ + 1))) '<=|'
If Tong > Temp Then
Temp = Tong: Ng = Cells(Cls.Row, "A").Value
Thg = jJ - 1
End If
End If
ElseIf Dem = SoNg Then '
If Cls.Value > 0 And Rng(1).Offset(1).Value > 0 And Rng(1).Offset(1, 1).Value > 0 Then
Tong = WF.Sum(Union(Cls, Rng(1).Offset(, 1).Resize(2)))
If Tong > Temp Then
Temp = Tong: Ng = Cells(Cls.Row, "A").Value
Thg = jJ - 1
End If
End If
End If
Next Cls
Next jJ
If Temp > 0 Then _
Max3Ngay = Temp & ", Ngày " & Right("0" & CStr(Ng), 2) & "/" & Right("0" & CStr(Thg), 2)
End Function