SYMPTOMS
When you run a Microsoft Visual Basic for Applications (VBA)
macro to transfer data from a VBA array that contains strings of data to a
range of cells in Microsoft Excel 2000 or in Microsoft Excel 2002, the data may
be truncated (cut off).
Note In Microsoft Office Excel 2003, you may receive the following
error message when you run the VBA macro in the Visual Basic Editor:
Run-time error '1004':
Application-defined or
object-defined error
If you run the VBA macro from your Excel
worksheet (on the
Tools menu, point to
Macro
and then click
Macros), you may receive the following error
message:
Microsoft Visual Basic:
400
WORKAROUND
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
To work around this problem, populate each
cell in your worksheet one at a time from the array, instead of populating the
whole range at one time.
To do this, use a VBA macro that is similar
to the following example:
Sub PopulateRangeWithArray()
Dim x
ReDim x(1 To 2, 1 To 2)
x(1, 1) = String(2000, "a"): x(1, 2) = String(5000, "b")
x(2, 1) = String(17000, "c"): x(2, 2) = String(33000, "d")
MsgBox Len(x(1, 1)) & "," & Len(x(1, 2)) _
& "," & Len(x(2, 1)) & "," & Len(x(2, 2))
Range("a1").Value = x(1, 1)
Range("b1").Value = x(1, 2)
Range("a2").Value = x(2, 1)
Range("b2").Value = x(2, 2)
End Sub
REFERENCES
For additional information,
click the following article number to view the article in the Microsoft
Knowledge Base:
166342
XL: Maximum Array Size in Microsoft Excel