The information in this article applies to:
SYMPTOMSIn Microsoft Excel, if you create a large array in a Visual Basic procedure, and use a worksheet function to return an element of the array, the incorrect value is returned. CAUSE
This behavior occurs because when you use a worksheet function to
access an element in a large array, Microsoft Excel assumes that the
elements wrap around, or start again at the 4096th element. Because of
this, the value of the 4096th element is returned as 0, the value of the
4097th element is returned as the value of the first element, the value of
the 4098th element is returned as the value of the second element, and so
on. =INDEX(Test(),5000)the value of the 904th element (5000-4096) is returned. Note that this behavior also occurs if you use the INDEX function in a Visual Basic procedure, as in the following example:
Note that this behavior does not occur when you use a Visual Basic
procedure to return an element of a large array, as in the following
example:
WORKAROUNDTo avoid returning the incorrect value for an element of an array, use a Visual Basic procedure to return the array element when your array contains more than 4096 elements. For example, to return the 5000th element in the array Test, use the following syntax:
Microsoft provides examples of Visual Basic procedures for
illustration only, without warranty either expressed or implied,
including but not limited to the implied warranties of merchantability
and/or fitness for a particular purpose. This Visual Basic procedure
is provided 'as is' and Microsoft does not guarantee that it can be
used in all situations. Microsoft does not support modifications of
this procedure to suit customer requirements for a particular purpose.Note that a line that is preceded by an apostrophe introduces a comment in the code--comments are provided to explain what the code is doing at a particular point in the procedure. STATUS
Microsoft has confirmed this to be a problem in the Microsoft products
listed at the beginning of this article. This problem was corrected in
Microsoft Excel versions 5.0c for Windows and 7.0 for Windows 95. Use the workaround provided above to avoid these errors. REFERENCESFor more information about the Function Statement, choose the Search button in the Visual Basic Reference and type: Function Additional query words: 1.00 5.00c 7.00
Keywords : |
Last Reviewed: September 21, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |