Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
错误';7';用excel2007在VBA中实现_Vba_Excel_Out Of Memory - Fatal编程技术网

错误';7';用excel2007在VBA中实现

错误';7';用excel2007在VBA中实现,vba,excel,out-of-memory,Vba,Excel,Out Of Memory,我正在Excel 2007中为VBA开发宏 还有一个部分用11列填充列表框。 有时,当我调用此方法重新填充信息时,会出现一条消息,其中显示: 在Ejeucción的tiempo中出现错误“7”:记忆 不足 在英语中是这样的: 运行时出现错误“7”:内存不足 代码指向这行代码: vList=ws.范围(“A2”,ws.范围(“A2”)。结束(xlDown)。结束(xlToRight)) 我保证通过将此函数中使用的所有对象设置为零来释放内存 这是我的完整代码: Function llenarDato

我正在Excel 2007中为VBA开发宏

还有一个部分用11列填充列表框。 有时,当我调用此方法重新填充信息时,会出现一条消息,其中显示:

在Ejeucción的tiempo中出现错误“7”:记忆 不足

在英语中是这样的:

运行时出现错误“7”:内存不足

代码指向这行代码:

vList=ws.范围(“A2”,ws.范围(“A2”)。结束(xlDown)。结束(xlToRight))

我保证通过将此函数中使用的所有对象设置为零来释放内存

这是我的完整代码:

Function llenarDatosTabla()

    Dim vList As Variant
    Dim ws As Worksheet: Set ws = Worksheets("PRODXSISTDATA")


    If (IsEmpty(ws.Range("A2").Value) = False) Then
        vList = ws.Range("A2", ws.Range("A2").End(xlDown).End(xlToRight))
        Me.ListBox1.List = vList
    End If

    Set vList = Nothing
    Set ws = Nothing
End Function

分别定义LastRow和LastCol,以便确保获取正确的范围

Dim LastRow As Long, LastCol As Long
'Dim your other stuff

If IsEmpty(ws.Range("A2").Value) = False) Then
    LastRow = Range("A" & Rows.Count).End(xlUp).Row
    LastCol = Cells(2, Columns.Count).End(xlToLeft).Column
    'Add this if still an issue to confirm correct LastRow and LastCol:
    'MsgBox "LastRow= " & LastRow & " LastCol= " & LastCol 
    vList = ws.Range(Cells(2, 1), Cells(LastRow, LastCol))
'etc etc etc

您对
vList=ws.Range(…
语句的赋值是确定区域中最后使用的单元格的错误方法。此错误最可能的原因是结果区域太大(因为它不是您认为应该的)。我建议您阅读以下答案:我得到一个“内存不足”异常,数组大小如下:
vList=Range(“A1”)。Resize(1048576,32)
。我在
中得到类似错误。Resize(2001,16384)
因此,一个数组中存储的单元格值大约有3300万个,这是在Excel 2010中的空工作表上测试的。