View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Stephen Bullen[_4_] Stephen Bullen[_4_] is offline
external usenet poster
 
Posts: 205
Default Option Explicit and Date Format "dd mmm yyyy"?

Hi Rob,

I agree - more controlled to pass variable as numeric.
However, I write .Value from a VBA Date datatype. Is there an advantage to
convert to Double - or does it get converted to Double anyway (behind the
scenes)?


If you write a Date data type to a cell, Excel also gives the cell a default
'date' number format. Similarly, if you write a string that looks like a
date, Excel gives it a format something like that used in the string. Both
those waste a few cycles if you then want to format the cell properly. I
tested it with the following (in which my regional settings are DMY order):

Sub Test()

'Got 38300.45299
Range("A1").Value = CDbl(Now())

'Got 09/11/2004 10:52
Range("A2").Value = CDate(Now())

'Got 09-Nov-04 (notice, NOT the same as the date string entered!)
Range("A3").Value = "9 Nov 2004"

End Sub


Regards

Stephen Bullen
Microsoft MVP - Excel
www.oaltd.co.uk