Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Hi Try var1 as string var1 = Cells(1, 1).Text I'd have thought the Variant declaration would do it, but it seems not. Anyone out there know why not? I couldn't find the type of an error in the Errors collection You could also do var1 as Variant var1 = Cstr(Cells(1,1).Value) but this returns Error 2042 regards Paul |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Hello Roshintosh & Paul, Worksheet cells are all variants. When an error is found, Excel set the cell to an Error type variant. This can be verified 2 ways. Firs by using IsError() and second by using VarType(). IsError will retur True if the cell is an Error variant type and VarType returns 10 if th cell is an Error variant type. To answer your question about getting a cell value, if there is a error Excel will only return the Error, not the value. So, your bes bet is test for an error and handle it. The help files tell you how to raise an error in cell, but not how t convert an Error type back to something useful like an Error Number Here's how to do that... Sub ErrorTest() Dim Ret Dim ErrNum Ret = Range("A1").Value If IsError(Ret) Then E = CInt(Ret) End If End Sub Hope this helps you some. Sincerely, Leith Ros -- Leith Ros ----------------------------------------------------------------------- Leith Ross's Profile: http://www.excelforum.com/member.php...fo&userid=1846 View this thread: http://www.excelforum.com/showthread.php?threadid=48380 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Help: Compile error: type mismatch: array or user defined type expected | Excel Programming | |||
type mismatch? | Excel Programming | |||
type mismatch here! | Excel Programming | |||
Type Mismatch | Excel Programming | |||
Type Mismatch | Excel Programming |