我在下面的子中遇到了溢出区域,我无法弄清楚原因。单步执行代码,lRows和lCols被设置为正确的值,redims在数组上设置正确的范围,但是当我尝试将范围值分配给数组时,它会失败(在线:arrData = rng.value) 。我的行常常达到90,000+左右,但是我有一切都很长,所以我认为这不会有问题......
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
答案 0 :(得分:0)