PDA

View Full Version : Obtaning current date time through VBA



volabos
02-12-2010, 01:48 PM
I would like to get current date and time with following format ""13-Feb-2005 17:19"". Is there any VBA code to get that?

Best regards,
: pray2:

GTO
02-12-2010, 02:12 PM
By example, for A1 of current sheet, try:
Option Explicit

Sub exa()
With Range("A1")

.NumberFormat = "d-mmm-yyyy Hh:Mm"
'// to return now
'.Value = Now()

'//to return ex date/time
.Value = DateSerial(2005, 2, 13) + TimeSerial(17, 19, 0)

.EntireColumn.AutoFit
End With
End Sub

Hope that helps,

Mark