Function BaNgay(Mang As Range)
Dim DD As Integer, DC As Integer
Dim CD As String, CC As String
Dim i As Integer, j As Integer
Dim LuongMua As Variant
Dim LM1 As Variant, LM2 As Variant, LM3 As Variant
Dim Ngay1 As Date, Ngay2 As Date, Ngay3 As Date
DD = Mang.Row: DC = DD + Mang.Rows.Count - 1
CD = Mang.Column: CC = CD + Mang.Columns.Count - 1
For i = CD To CC
For j = DD To DC - 2
If (Cells(j, i) + Cells(j + 1, i) + Cells(j + 2, i)) > LuongMua Then
LuongMua = Cells(j, i) + Cells(j + 1, i) + Cells(j + 2, i)
LM1 = Format(Cells(j, i), "#,#00.00")
LM2 = Format(Cells(j + 1, i), "#,#00.00")
LM3 = Format(Cells(j + 2, i), "#,#00.00")
Ngay1 = DateSerial(2007, i - (CD - 1), j - (DD - 1))
Ngay2 = DateSerial(2007, i - (CD - 1), j + 1 - (DD - 1))
Ngay3 = DateSerial(2007, i - (CD - 1), j + 2 - (DD - 1))
End If: Next: Next
BaNgay = " - Ngay " & Ngay1 & ": " & LM1 & Chr(10) & " - Ngay " & Ngay2 & ": " & LM2 & Chr(10) & " - Ngay " & Ngay3 & ": " & LM3 & Chr(10) & " - Tong luong mua : " & Format(LuongMua, "#,#00.00")
End Function