Dear Experts,
I have a large array I need to dump to a range. I read that there are limits on the size of array you can dump, so I wrote this sub to prevent writing too much to the sheet at once. I still get an error when writing row 1385, column 11. This item of data is a string that is only about 75 characters in length.
In fact, I have isolated the problem such that I can't even assign the individual element of the array to an individual cell. In the immediate window I used:
which causes the run time error 1004: Application-defined or object-defined error.
In the immediate window I have:
Note that clean trim is a sub that clears out all the special characters of the string. I am not sure if trying to put a special character in a cell would cause an issue anyhow.
So, here's my sub. Don't laugh too hard as I am still a VBA novice.
Any help would be greatly appreciated!! Thank you for your time.
I have a large array I need to dump to a range. I read that there are limits on the size of array you can dump, so I wrote this sub to prevent writing too much to the sheet at once. I still get an error when writing row 1385, column 11. This item of data is a string that is only about 75 characters in length.
In fact, I have isolated the problem such that I can't even assign the individual element of the array to an individual cell. In the immediate window I used:
Code:
myrange(85,11)=subsnap(85,11)
which causes the run time error 1004: Application-defined or object-defined error.
In the immediate window I have:
Code:
? typename(subsnap(85,11))
String
? len(subsnap(85,11))
76
? subsnap(85,11)=CleanTrim(subsnap(85,11))
True
So, here's my sub. Don't laugh too hard as I am still a VBA novice.
Code:
Sub RangeDump(Snapshot() As Variant)
'Snapshot is an array roughly 10000 x 50, some elements in the array are long strings
' Row is used in a loop to increment through the array
' MyRange is used to define a range on the spreadsheet to dump part of the array
' SubSnap is a subset of the full snapshot array
' Index is a counter to limit the size of the subset array
' col is used in a loop to increment the columns of the array
Dim Row As Long
Dim MyRange As Range
Dim SubSnap(1 To 100, 1 To 100) As Variant
Dim Index As Long
Dim Col As Integer
'dumping to Sheet 2 until this is debugged
With ThisWorkbook.Sheets("Sheet2")
'setting the range equal to the size of the subset array. I thought this was clever
Set MyRange = Range(.Cells(1, 1), .Cells(UBound(SubSnap, 1), UBound(SubSnap, 2)))
End With
Index = 1
For Row = 1 To UBound(Snapshot, 1)
For Col = 1 To UBound(Snapshot, 2)
SubSnap(Index, Col) = Snapshot(Row, Col)
Next Col
If Index = UBound(SubSnap, 1) Then
'hit the limit of what subsnap can hold - dump it
MyRange = SubSnap()
Set MyRange = MyRange.Offset(Index, 0)
Erase SubSnap
Index = 0
End If
Index = Index + 1
Next Row
MyRange.RowHeight = 30
Stop
End Sub
Any help would be greatly appreciated!! Thank you for your time.