Option Explicit
Function listngay(ngaybd As Date, songay As Integer, n As Integer) As String
If ngaybd = 0 Or songay = 0 Then
listngay = "O nay khong co so lieu!"
Exit Function
End If
Dim c&, st As String, ngaykt As Date, wf As Object
Set wf = WorksheetFunction
Do
c = c + 1
Select Case n
Case 1
ngaybd = IIf(c = 1, ngaybd, ngaykt)
ngaykt = wf.Min(Date, wf.WorkDay_Intl(ngaybd, songay, "0000000", Sheets("LICH NGHI LE").Range("A2:A5")))
Case 2
ngaybd = ngaybd + songay
ngaykt = wf.Min(Date, wf.WorkDay_Intl(ngaybd - 1, 1, "0000000", Sheets("LICH NGHI LE").Range("A2:A5")))
Case Else
MsgBox "Nhap 1 hay 2 cho tham so thu 3!"
Exit Function
End Select
st = IIf(st = "", ngaykt, st & ", " & ngaykt)
If ngaykt >= Date Then Exit Do
Loop
listngay = st
End Function