Thread: run time error
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default run time error

Hi Mike,

If the cell's value cannot be interpreted as a date, the code will fail with
a type mismatch error.

Try:
'=============
Sub test()
Dim maturitydate As Date

With Cells(1, 1)
If IsDate(.Value) Then
maturitydate = .Value
End If
End With

End Sub
'<<=============

---
Regards,
Norman



"mike allen" wrote in message
...
why would code such as this cause an error?
sub test()
dim maturitydate as date
maturitydate=cells(1,1)
end sub

cells(1,1), in this particular case, is empty, or so it seems. the
spreadsheet formula in cells(1,1) is: =""
when cells(1,1) is 6/30/06 it runs fine.
when formula has ="" i expect code to return 'empty', but it stops for
some reason. thx