I promise I've searched for a solution but can't find anything to help me here. I am working on a procedure that will search between two reasonably sized ranges (less than 200 records) to make sure every ID number in one range is represented in the other. If a record is missing, a UserForm is prompted. I am getting a VBA out of memory error when the userform chooses to delete a record. I don't think I have any significant memory leaks, but can't seem to reorganize this to solve the problem. I have posted the code below.
I've never asked a question on here before, so please let me know if I need to provide any additional information. Thanks!
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