Error Message If Array Contains More Than 2,730 Elements

Last reviewed: September 2, 1997
Article ID: Q137921
The information in this article applies to:
  • Microsoft Excel for Windows NT, version 5.0
  • Microsoft Excel for Windows 95, version 7.0

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 engineers 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

REFERENCES

"Visual Basic User's Guide," version 5.0, Chapter 6, "Working with Visual Basic Code in Procedures"

For more information about Arrays In Microsoft Excel 7.0, click Answer Wizard on the Help menu, and type:

   What is an array?

Keywords          : kbcode kberrmsg kbprg PgmOthr xlwin
Version           : WINDOWS:5.0;7.0
Platform          : WINDOWS
Issue type        : kbprb


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 2, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.