Option Explicit
Public Sub NgayGio_by_Maika8008()
Dim K As Long, R As Long, i As Long, tmp As Long, tmp2 As Long, lrow As Long, sDate As Long
Dim sTime As String
Dim arr, arr2
Dim S As Double, j As Long, T As Long, C As Long, x As Long, SD As Long
sDate = Range("D2")
sTime = CStr(Range("E2").Text)
K = Range("A2") 'Thay doi gia tri tu 1 den 59 phut
R = Range("C2")
lrow = Range("B2") 'Thay doi dong cuoi can lam
x = lrow Mod R
arr = Range("D2:E" & R + 1).Value
If lrow < R Then
MsgBox "Tong so dong khong duoc nho hon so dong cua 1 bang!"
Exit Sub
End If
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
T = Int(lrow / R) + 1
For j = 1 To T
C = 3 * j + 1
SD = IIf(j < T, R, x)
For i = 1 To SD
If i > 1 And i < SD + 1 Then
tmp = Right(arr(i - 1, 2), 2)
tmp2 = Left(arr(i - 1, 2), 2)
tmp = tmp + K
If tmp >= 60 Then
tmp2 = tmp2 + 1
tmp = tmp - 60
If tmp2 = 24 Then
tmp2 = 0
sDate = sDate + 1
End If
End If
arr(i, 2) = Right("0" & tmp2, 2) & ":" & Right("0" & tmp, 2)
arr(i, 1) = sDate
End If
Next
Cells(2, C).Resize(50000, 2).ClearContents
Cells(2, C).Resize(SD, 2) = arr
Cells(2, C).Resize(SD, 1).NumberFormat = "dd/mm/yyyy"
sDate = arr(SD, 1)
sTime = arr(SD, 2)
arr(1, 1) = sDate
arr(1, 2) = IIf(Left(arr(SD, 2), 2) & ":" & Right("0" & Right(arr(SD, 2), 2) + 1, 2) = "23:60", _
"00:00", Left(arr(SD, 2), 2) & ":" & Right("0" & Right(arr(SD, 2), 2) + 1, 2))
Next
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub