内存不足,无法找到泄漏

时间:2018-03-22 16:27:08

标签: excel vba excel-vba

我保证我已经找到了解决方案,但在这里找不到任何帮助我的方法。我正在研究一个程序,它将在两个合理大小的范围(少于200条记录)之间进行搜索,以确保一个范围内的每个ID号都在另一个范围内表示。如果缺少记录,则会提示用户窗体。当userform选择删除记录时,我收到VBA内存不足错误。我不认为我有任何重大的内存泄漏,但似乎无法重组这个以解决问题。我已经发布了以下代码。

我之前从未问过这里的问题,所以如果我需要提供任何其他信息,请告诉我。谢谢!

Public UFTargetCell As Range

Sub RxConfirmation2()

Dim RxWbk As Variant
Dim RxWks As Worksheet
Dim ConRDCol As Range
Dim ConRxCol As Range
Dim ConRxCell As Range
Dim OpsMetRxTemp As Worksheet
Dim C As Range

'Defines some variables using another procedure
FlagInit

'Opens Rx Selected Rx Chart

Set OpsMetRxTemp = Sheets.Add(After:=OpsMetWbk.Worksheets(2))
OpsMetRxTemp.Name = "RxTemp"

RxWbk = Application.GetOpenFilename(FileFilter:="Excel File (*.xlsm), *.xlsm")
Set RxWbk = Workbooks.Open(RxWbk)
Set RxWks = RxWbk.Sheets(1)
RxWks.Activate
RxWks.ListObjects("TableRx").Range.Copy
OpsMetRxTemp.Activate
OpsMetRxTemp.Range("A1").PasteSpecial
Application.CutCopyMode = False
RxWbk.Close

Set ConRDCol = RDSheet.Range("ImportRange").Columns("E")
Set ConRxCol = OpsMetRxTemp.Range("TableRx[Consultation ID]")

'Memory issue in here somewhere? Problem occurs when user opts to delete record. Code for that form is below.

For Each ConRxCell In ConRxCol
    Set C = ConRDCol.Find(ConRxCell, LookIn:=xlValues)
    ConRxCell.Select
    If C Is Nothing Then
        Set UFTargetCell = ConRxCell
        AddOrRemRecForm.Show

    Else:
        If C.Offset(, 29).Value <> ConRxCell.Offset(0, 1).Value Then
            C.Offset(, 29).Value = ConRxCell.Offset(0, 1).Value
            FlagUpdate (9)
        End If
    End If
    Next

Application.DisplayAlerts = False
OpsMetRxTemp.Delete
Application.DisplayAlerts = True

End Sub

Private Sub CommandButtonDel_Click()

UFTargetCell.Rows.Delete
Set UFTargetCell = Nothing
Unload Me

End Sub

0 个答案:

没有答案