Why does my string snap?

Kelvin Stott

Active Member
Joined
Oct 26, 2010
Messages
338
Hello,

I have written the following function in VBA, which converts a 1-dimensional data array into a text string by concatenating successive data points separated by a comma. The string is defined as variable length with no fixed limit, and I had understood this should allow for about 2 billion characters, but the function generates an error ("wrong data type") as the string exceeds about 64,000 characters. Is there any way to extend/avoid this limit?

Code:
Function DSTORE(DArray)
'Converts a 1-dimensional data array into a text string, with successive data points separated by a comma

    Dim d As Long
    Dim DText As String    'Variable length string with no fixed limit
    
    For d = LBound(DArray) To UBound(DArray)
        DText = DText & DArray(d) & ","
    Next d

    DSTORE = DText

End Function

Thanks for any help with this!

Best regards,
Kelvin
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Does this work for you?

Code:
Function DSTORE(DArray)
'Converts a 1-dimensional data array into a text string, with successive data points separated by a comma
    DSTORE = Join(DArray, ",")
End Function
 
Upvote 0
Ouch, it seems that the limit is actually driven by the capacity of an individual cell, when I try to use the formula in a worksheet.

What is the maximum capacity (no. of characters) of a cell? Does this vary in different versions of Excel?
 
Upvote 0

Forum statistics

Threads
1,216,084
Messages
6,128,722
Members
449,465
Latest member
TAKLAM

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top