View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Harald Staff[_2_] Harald Staff[_2_] is offline
external usenet poster
 
Posts: 449
Default VB Format command fails

Hi Kirk

The others explained about types. Problem also is that it won't convert a
month-like text without a day to a valid date, therefore the type mismatch.
So let's avoid that one:

Sub test()
Dim S As String
Dim D As Date
'S = Cells(1, 1).Value 'or
S = "00/11/1975"
S = Replace(S, "00/", "01/")
D = DateValue(S)
MsgBox Format(D, "dddd dd.mm.yy") & vbNewLine & _
Format(D, "mmm yyyy")
End Sub

HTH. Best wishes Harald

"kirkm" wrote in message ...

Hi,

Anyone know what's wrong here?

Cell(1,1) contains "00/11/1975" as text.

Dim v as Date
v = Format(.Cells(1, 1), "mmm yyyy")

If v is dimmed as a Variant the format is unchanged
and in the above example returns 'type mismatch'.

Have spend a long time trying all sorts of variations
without success.

Thanks - Kirk