XL5: Incorrect Result Using Large Array in Worksheet Function |
In 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.
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.
This problem occurs when you use the INDEX function to return an
element in a large array. For example, if you use the Visual Basic
function Test to return an array of 6000 elements, and you use this
array in the following function on a worksheet
=INDEX(Test(),5000)the value of the 904th element (5000-4096) is returned.
MsgBox Application.Index(Test(),5000)
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:
MsgBox Test(5000)
To 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:
result = Test(5000)
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.
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.
Note that in Microsoft Excel versions 5.0c and 7.0, you cannot use an array
that has greater than 4096 elements in a worksheet function. The #VALUE!
error value is returned when you use an array with greater than 4096
elements in a function on a worksheet. If you use a worksheet function
such as INDEX in a Visual Basic procedure with an array that contains
more than 4096 elements, you receive the following error message:
Use the workaround provided above to avoid these errors.Run-time error '1004':
Index method of Application class failed
For 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 :
Version : 5.00
Platform : WINDOWS
Issue type :
Technology :
|
Last Reviewed: September 21, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |