Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm getting an Overflow area in the following sub, and I can't figure out why. Stepping through the code, lRows and lCols gets set to the correct values, and the redims set the correct ranges on the arrays, but it fails when I try to assign the range values to the array (on line: arrData = rng.value). My rows do often go up to around 90,000+, but I have everything as long, so I would think that wouldn't be a problem...

Sub test()
Dim arrData() As Variant
Dim arrReturnData() As Variant
Dim rng As Excel.Range
Dim lRows As Long
Dim lCols As Long
Dim i As Long, j As Long

lRows = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
lCols = ActiveSheet.Range("A1").End(xlToRight).Column

ReDim arrData(1 To lRows, 1 To lCols)
ReDim arrReturnData(1 To lRows, 1 To lCols)
Set rng = ActiveSheet.Range(Cells(1, 1), Cells(lRows, lCols))
arrData = rng.value ' Overflow error on this line
For j = 1 To lCols
    For i = 1 To lRows
        arrReturnData(i, j) = Trim(arrData(i, j))
    Next i
Next j

rng.value = arrReturnData
End Sub
share|improve this question
    
What you're doing is not anything I've tried, but I've never seen anybody try to set an array that way. Do you get the same result if you copy cell by cell? –  Ann L. Nov 6 '13 at 20:10
    
Just had a mini-stroke, and suddenly it dawned on me to try .Value2 instead of .value. Fixed the problem right up. –  Methonis Nov 6 '13 at 20:17
    
You don't need to ReDim arrData. In fact you should declare arrData As Variant, not as an array. –  Jean-François Corbett Nov 7 '13 at 8:45

1 Answer 1

up vote 0 down vote accepted

try

Dim arrData as Variant
arrData = Range(Cells(1, 1), Cells(lRows, lCols))

and for more info see this answer

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.