View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default Convert number to date

The value 20081012 is not a proper date format, so CDate cannot convert it.
Try this instead (no need for your 'a' variable, you can assign to 'b'
variable directly)...

Sub anders()
b = CDate(Format(Range("A1").Value, "0000-00-00"))
End Sub

--
Rick (MVP - Excel)


"Arne Hegefors" wrote in message
...
Hi! I am trying to convert a string to a date. however i get Error nr6
"spill".

in cell A1 I have a date written like this "20081012"

Sub anders()
Dim a As Long
a = Range("a1").Value
b = CDate(a)
End Sub


I get the error when trying to convert to date, pls hepl