PDA

View Full Version : Date conundrum



mdmackillop
01-18-2006, 02:10 PM
For UK language setup only

Try the following. Enter 1/2/06 in the input box

Sub InsertDate()
Range("A1:A2").NumberFormat = "dd mmmm yyyy"
tmp = InputBox("Insert date")
[A1] = tmp
[A2] = DateValue(tmp)
End Sub

My Result
A1 = 02 January 2006
A2 = 01 February 2006

Philcjr
01-18-2006, 02:23 PM
I tried it and got:
A1 = 02 January 2006
A2 = 02 January 2006

I had to add
Dim tmp as Date

Hope this helps, Phil

Bob Phillips
01-18-2006, 04:26 PM
For UK language setup only

Try the following. Enter 1/2/06 in the input box

Sub InsertDate()
Range("A1:A2").NumberFormat = "dd mmmm yyyy"
tmp = InputBox("Insert date")
[A1] = tmp
[A2] = DateValue(tmp)
End Sub

My Result
A1 = 02 January 2006
A2 = 01 February 2006

VBA talks American English Malcolm. You always have to cast dates for Excel.

For example


[A1] = CDate(tmp)