XL97: Len Function Returns Only 1024 Characters in Cell

ID: Q157306

The information in this article applies to:

SYMPTOMS

In a Microsoft Visual Basic for Applications macro in Microsoft Excel 97, if you use the Len function to calculate the number of characters in an object, such as a cell, you may receive the incorrect result, 1024.

CAUSE

This occurs if the following conditions are true:

The Text property of an object returns only the first 1024 characters in the object.

This behavior is by design of the Text property in Microsoft Excel.

WORKAROUND

To determine the correct number of characters within an object, use the Value property within the Len function, as in the following example:

   Len(ActiveCell.Value)

MORE INFORMATION

You can use the Len function in Visual Basic for Applications to calculate the number of characters within a cell in a worksheet or within any other object that contains text.

If you use the Len function to calculate the number of characters contained in an object, and if you use the Text property of the object, the maximum result is 1024. This may cause problems if the object in question contains more than 1024 characters.

For additional information about the Text property in Microsoft Excel, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q157350
   TITLE     : XL97: Text Property Limited to 1024 Characters

Additional query words: XL97 32,767 length
Keywords          : kbprg kbdta xlvbainfo KbVBA 
Version           : WINDOWS:97
Platform          : WINDOWS
Issue type        : kbprb

Last Reviewed: January 8, 1999