Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default populating cells with array bug?

Microsoft documents that the largest number of characters that can be in a
cell value is 32,767. I verified this is the case using code similar to the
vba below. However, there is different behavior depending on how I set the
value programmatically. If I set the cell value from an array (which I
normally do when populating multiple values at once -- ex. a two-dimensional
array of values to populate a rectangular range), an exception occurs if the
value is longer than some arbitrary amount (around 910 in my case below).
The error, "Application-defined or object-defined error" is not helpful.
Why does it fail when populating via array? Seems like a bug to me unless
there is another limitation I'm not aware of. See vba below that reproduces
the problem.

Thanks,
Casey

Sub MaxValueLengthTest()

On Error GoTo ErrHandler

Dim i As Integer
Dim vals(1) As Variant
Dim maxLengthValue As String

'build a string with 32767 characters -- the max supported per cell
For i = 1 To 3276
maxLengthValue = maxLengthValue & "0123456789"
Next i
maxLengthValue = maxLengthValue & "0123456"

'both simple cases work
vals(0) = "simple"
Range("A1").Value = vals(0)
Range("A2").Value = vals

vals(0) = maxLengthValue
Range("B1").Value = vals(0) 'setting from the string works
Range("B2").Value = vals 'setting via the array fails -- in my
testing it starts failing when a value in this array is more than approx.
910 characters

Exit Sub

ErrHandler:
MsgBox Err.Description
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 298
Default populating cells with array bug?

http://support.microsoft.com/kb/818808

Tim


"Casey" wrote in message
...
Microsoft documents that the largest number of characters that can be in a
cell value is 32,767. I verified this is the case using code similar to
the vba below. However, there is different behavior depending on how I
set the value programmatically. If I set the cell value from an array
(which I normally do when populating multiple values at once -- ex. a
two-dimensional array of values to populate a rectangular range), an
exception occurs if the value is longer than some arbitrary amount (around
910 in my case below). The error, "Application-defined or object-defined
error" is not helpful. Why does it fail when populating via array? Seems
like a bug to me unless there is another limitation I'm not aware of. See
vba below that reproduces the problem.

Thanks,
Casey

Sub MaxValueLengthTest()

On Error GoTo ErrHandler

Dim i As Integer
Dim vals(1) As Variant
Dim maxLengthValue As String

'build a string with 32767 characters -- the max supported per cell
For i = 1 To 3276
maxLengthValue = maxLengthValue & "0123456789"
Next i
maxLengthValue = maxLengthValue & "0123456"

'both simple cases work
vals(0) = "simple"
Range("A1").Value = vals(0)
Range("A2").Value = vals

vals(0) = maxLengthValue
Range("B1").Value = vals(0) 'setting from the string works
Range("B2").Value = vals 'setting via the array fails -- in my
testing it starts failing when a value in this array is more than approx.
910 characters

Exit Sub

ErrHandler:
MsgBox Err.Description
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default populating cells with array bug?

For i = 1 To 3276
maxLengthValue = maxLengthValue & "0123456789"
Next i


HI. Just a different idea for building the string...

Sub Demo()
Dim v
Const s As String = "1234567890"
v = WorksheetFunction.Rept(s, 3276)
Debug.Print Len(v)
End Sub

= = = = = =
HTH
Dana DeLouis


Casey wrote:
Microsoft documents that the largest number of characters that can be in a
cell value is 32,767. I verified this is the case using code similar to the
vba below. However, there is different behavior depending on how I set the
value programmatically. If I set the cell value from an array (which I
normally do when populating multiple values at once -- ex. a two-dimensional
array of values to populate a rectangular range), an exception occurs if the
value is longer than some arbitrary amount (around 910 in my case below).
The error, "Application-defined or object-defined error" is not helpful.
Why does it fail when populating via array? Seems like a bug to me unless
there is another limitation I'm not aware of. See vba below that reproduces
the problem.

Thanks,
Casey

Sub MaxValueLengthTest()

On Error GoTo ErrHandler

Dim i As Integer
Dim vals(1) As Variant
Dim maxLengthValue As String

'build a string with 32767 characters -- the max supported per cell
For i = 1 To 3276
maxLengthValue = maxLengthValue & "0123456789"
Next i
maxLengthValue = maxLengthValue & "0123456"

'both simple cases work
vals(0) = "simple"
Range("A1").Value = vals(0)
Range("A2").Value = vals

vals(0) = maxLengthValue
Range("B1").Value = vals(0) 'setting from the string works
Range("B2").Value = vals 'setting via the array fails -- in my
testing it starts failing when a value in this array is more than approx.
910 characters

Exit Sub

ErrHandler:
MsgBox Err.Description
End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default populating cells with array bug?

For i = 1 To 3276
maxLengthValue = maxLengthValue & "0123456789"
Next i


HI. Just a different idea for building the string...

Sub Demo()
Dim v
Const s As String = "1234567890"
v = WorksheetFunction.Rept(s, 3276)
Debug.Print Len(v)
End Sub


You can get the same end result that your code produces using built-in VB
functions...

Sub Demo()
Dim v
Const s As String = "1234567890"
v = Replace(String(3276, "X"), "X", s)
Debug.Print Len(v)
End Sub

--
Rick (MVP - Excel)

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default populating cells with array bug?

Const s As String = "1234567890"
v = Replace(String(3276, "X"), "X", s)


Thanks Rick! Didn't think of that. Nice!
Dana DeLouis



On 10/14/09 1:22 PM, Rick Rothstein wrote:
For i = 1 To 3276
maxLengthValue = maxLengthValue & "0123456789"
Next i


HI. Just a different idea for building the string...

Sub Demo()
Dim v
Const s As String = "1234567890"
v = WorksheetFunction.Rept(s, 3276)
Debug.Print Len(v)
End Sub


You can get the same end result that your code produces using built-in
VB functions...

Sub Demo()
Dim v
Const s As String = "1234567890"
v = Replace(String(3276, "X"), "X", s)
Debug.Print Len(v)
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Populating a ListBox with an Array ironhydroxide Excel Programming 1 August 2nd 09 04:03 AM
Populating an array Bucs85027 Excel Worksheet Functions 0 February 14th 08 12:32 AM
populating a listbox from an array Graham Whitehead Excel Programming 2 August 2nd 06 01:11 PM
populating listview with array RB Smissaert Excel Programming 2 September 1st 04 05:41 PM
Populating a 2-D array Hotbird[_2_] Excel Programming 8 February 7th 04 05:25 PM


All times are GMT +1. The time now is 10:39 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"