[英]error '7' in VBA with Excel 2007
我正在為Excel 2007中的VBA開發宏
還有一個部分用11列填充ListBox。 有時,當我調用此方法重新填充信息時,會出現一條消息,內容為:
在生產過程中出現錯誤“ 7”:記憶不足
用英語是這樣的:
運行時出現錯誤“ 7”:內存不足
代碼指向這一行代碼:
vList = ws.Range(“ A2”,ws.Range(“ A2”)。End(xlDown).End(xlToRight))
我保證通過將此函數上使用的所有對象設置為Nothing釋放內存
這是我的完整代碼:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.