Date Format - Enclosed with #Date#
Private Sub CommandButton1_Click()
Dim i As Integer, j As Date
j = #10/1/2015#
For i = 1 To 15
Cells(i, 1).Value = j
j = j + 1
Next
Columns(1).AutoFit
End Sub
Date Format - Single date multple times
Private Sub CommandButton1_Click()
Dim i As Integer
For i = 1 To 15
Cells(i, 1).Value = #1/1/2016#
Next
End Sub
Now
Private Sub CommandButton1_Click()
Range("A1").Value = Now
MsgBox Now
End Sub
Date
Private Sub CommandButton1_Click()
MsgBox Date
Range("A1").Value = Date
End Sub
Year
Private Sub CommandButton1_Click()
Range("A1").Value = Year("1 - Oct - 2016")
End Sub
Time
Private Sub CommandButton1_Click()
MsgBox Time
Range("A1").Value = Time
End Sub
Day Function
Private Sub CommandButton1_Click()
Range("A1").Value = Day("1-oct-2016")
Range("A2").Value = Day("15-oct-2016")
End Sub
Month Function
Private Sub CommandButton1_Click()
MsgBox Month("1-Oct-2016")
Range("A1").Value = Month("1-Oct-2016")
End Sub
Hour Function
Private Sub CommandButton1_Click()
MsgBox Hour("23:15")
Range("A1").Value = Hour("23:15")
End Sub
Second Function
Private Sub CommandButton1_Click()
MsgBox Second("17:35:49")
Range("A1").Value = Second("17:18:49")
Range("A2").Value = Second("23:35:49")
End Sub
Date Functions
Sub Createdates()
Range("A1").Value = Now()
Range("A2").Value = Date
Range("A3").Value = Year(Date)
Range("A4").Value = Month(Date)
Range("A5").Value = Day(Date)
Range("A6").Value = Time
Range("A7").Value = Weekday(Date)
Range("A8").Value = MonthName(Month(Date))
'MsgBox DateSerial(2016, 1, 0)
Range("A9").Value = Day(DateSerial(2016, 4, 0))
End Sub