In VBA use Dateserial() like:
Sub dural()
y = 2014
m = 3
d = 2
Range("A1").NumberFormat = "dd/mm/yyyy hh:mm:ss"
Range("A1").Value = DateSerial(y, m, d)
End Sub
Note the order of parameters!
Вопрос
I want to use the date function in an Excel VBA script using a parameter value.
D = "=Date(y,m,d)"
where d
, m
, y
are parameters that are fetched during running the macro.
The problem for me is that I have to maintain the date format for the cell like "dd/mm/yyyy hh:mm:ss"
.
Решение
In VBA use Dateserial() like:
Sub dural()
y = 2014
m = 3
d = 2
Range("A1").NumberFormat = "dd/mm/yyyy hh:mm:ss"
Range("A1").Value = DateSerial(y, m, d)
End Sub
Note the order of parameters!