Microsoft KB Archive/137921

= Error Message Appears If Array Contains More Than 2,730 Elements =

Article ID: 137921

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Excel 95 Standard Edition
 * Microsoft Excel 5.0 Standard Edition

-



This article was previously published under Q137921



SYMPTOMS
In Microsoft Excel 5.0 for Windows NT and Microsoft Excel 7.0, an array in a macro can contain a maximum of 2,730 elements. If you create an array definition that exceeds this limit, you receive the following error message:

Run-time error 1006

Unable to get the value property of the range class

Note that this behavior is different from Microsoft Excel version 5.0 and earlier versions for Windows. In these versions of Microsoft Excel, an array macro definition can contain up to 3,276 elements.



CAUSE
This problem occurs because array definitions are limited to one 65,536- byte (64K) segment of memory. In the 32-bit versions of Microsoft Excel, a value is stored in 24 bits. Because an array definition cannot exceed one segment of memory, the number of elements that can be stored in an array cannot exceed 2,730.



MORE INFORMATION
In earlier versions of Microsoft Excel, the memory allocated a value was limited to 20 bits per value.

The 64K-per-segment limit is imposed by hardware interface methods currently in use.

The behavior described in this article is a problem only when you are creating an array from a worksheet range. If you create the array in Visual Basic for Applications, you do not experience this limit.

Microsoft provides examples of Visual Basic for Applications 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. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft Support professionals can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

The following macro creates an array with 10,000 elements: Sub MyArray Dim MyArray(1 To 10000) For element 1 To 10000

MyArray(element) = element Next element EndSub

