Quantcast
Channel: Excel: type() and WorksheetFunction.IsText() fail for long strings - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Excel: type() and WorksheetFunction.IsText() fail for long strings

$
0
0

Do other people find the following behavior? I'm running Excel 2007 under Windows 7.

In Excel VBA:

Public Function bTest_IsText(vArg As Variant) As BooleanbTest_IsText = WorksheetFunction.IsText(vArg)End FunctionPublic Function nTest_VarType(vArg As Variant) As IntegernTest_VarType = VarType(vArg)End Function

In Excel worksheet:

A1: =REPT("-", 255)A2: =REPT("-", 256)A3: =ISTEXT(A1)B3: =bTest_IsText(A1)C3: =TYPE(A1)D3: =nTest_VarType(A1)A4: =ISTEXT(A2)B4: =bTest_IsText(A2)C4: =TYPE(A2)D4: =nTest_VarType(A2)

Cells A3:D4 result:

TRUE   TRUE     2   8TRUE   FALSE   16   8

The return values 2 and 16 of type() have the meaning"Text" and "Error value", respectively. The return value 8 (= vbString) of VarType() has the meaning"String".

So it appears that type() in Excel and WorksheetFunction.IsText() in Excel VBA do not work if the argument passed to them has more than 255 characters. IsText() in Excel does not have this limitation. A workaround for the failure of WorksheetFunction.IsText() is to test for VarType(...) = vbString (which may be better anyway).

Are these legitimate bugs or am I doing something wrong?

Is there a place where verified bugs are compiled so I don't have to wonder if I'm going crazy when I see something like this?


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images