Public Sub DinhdangDate()
Dim Rgn As Range
Dim Rgn2 As Range
Dim dd As Date
Dim st, sd, sm, sy As String
Dim i As Integer
On Error GoTo Thoat
Set Rgn = Application.InputBox("Chon vung muon doi ngay!", "Chon vung", Selection.Address, , , , , 8)
On Error GoTo Thoat
Set Rgn2 = Application.InputBox("Chon vi tri o KQ max min!", "Chon o", Selection.Address, , , , , 8)
If Rgn2.Cells.Count > 1 Then Set Rgn2 = Cells(Rgn2.Row, Rgn2.Column)
i = 0
For Each st In Rgn
i = i + 1
If st <> "" Then
sd = Left(st, InStr(st, "/") - 1)
sm = Mid(st, InStr(st, "/") + 1, InStr(InStr(st, "/") + 1, st, "/") - InStr(st, "/") - 1)
sy = Right(st, Len(st) - InStrRev(st, "/"))
dd = DateSerial(Int(Val(sy)), Int(Val(sm)), Int(Val(sd)))
Rgn(i, 1) = dd
End If
Next
With Rgn
.NumberFormat = "dd/mm/yyyy"
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
End With
Rgn2 = "Max:": Rgn2.Offset(1, 0) = "Min:"
With Rgn2.Offset(0, 1)
.Offset(0, 1).NumberFormat = "dd/mm/yyyy"
.Font.Bold = True
.Formula = "=MAX(" + Rgn.Address + ")"
End With
With Rgn2.Offset(1, 1)
.Offset(0, 1).NumberFormat = "dd/mm/yyyy"
.Font.Bold = True
.Formula = "=MIN(" + Rgn.Address + ")"
End With
Thoat:
End Sub