Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

You may receive a "Run-time error 1004" error message when you programmatically set a large array string to a range in Excel 2003


View products that this article applies to.

Symptoms

In Office Excel 2003, when you programmatically set a range value with an array containing a large string, you may receive an error message similar to the following:
Run-time error '1004'.
Application-defined or operation-defined error.

↑ Back to the top


Cause

This issue may occur if one or more of the cells in an array (range of cells) contain a character string that is set to contain more than 911 characters.

↑ Back to the top


Workaround

To work around this issue, edit the script so that no cells in the array contain a character string that holds more than 911 characters.

For example, the following line of code from the example code block below defines a character string that contains 912 characters:
Sub XLTest()
Dim aValues(4)
 
  aValues(0) = "Test1"
  aValues(1) = "Test2"
  aValues(2) = "Test3"
 
  MsgBox "First the Good range set."
  aValues(3) = String(911, 65)
  
  Range("A1:D1").Value = aValues
 
  MsgBox "Now the bad range set."
  aValues(3) = String(912, 66)
  Range("A2:D2").Value = aValues
 
End Sub

↑ Back to the top


More information

A character string is a series of characters that are manipulated as a group. The length of a character string is typically the number of characters in it, or the length is pre-defined, as it is in this case.

↑ Back to the top


Keywords: KB818808, kbbug, kberrmsg

↑ Back to the top

Article Info
Article ID : 818808
Revision : 2
Created on : 9/19/2011
Published on : 9/19/2011
Exists online : False
Views : 233