我在以下代码块中遇到内存不足错误。有没有人看到一个明显的原因?
编辑代码以显示整个块。最终这将遍历一个目录,但在工作之前我只会查看一个文件。
Sub Get_BT_Data()
Dim fNameAndPath, data As Variant
Dim j, c, r As Integer
fNameAndPath = Application.GetOpenFilename(FileFilter:="Excel Files (*.XLSM), *.XLSM", Title:="Select File To Be Opened")
If fNameAndPath = False Then Exit Sub
Workbooks.Open Filename:=fNameAndPath
Sheets("Summary For CDP").Activate
j = Range("A2").Value
c = Range("B2").Value
data = Range("DataRay")
ThisWorkbook.Activate
r = Cells(7, 4).End(xlDown).Row
For i = 7 To r
If Cells(i, 4).Value = j Then
If Cells(i, 4).Offset(0, 1).Value = c Then
Cells(i, 4).Offset(0, 3).Value = data(9, 20)
Cells(i, 4).Offset(0, 4).Value = data(22, 22)
Cells(i, 4).Offset(0, 7).Value = data(2, 20)
Cells(i, 4).Offset(0, 8).Value = data(15, 22)
Cells(i, 4).Offset(0, 10).Value = data(5, 20)
Cells(i, 4).Offset(0, 11).Value = data(18, 22)
Cells(i, 4).Offset(0, 13).Value = data(3, 22)
Cells(i, 4).Offset(0, 14).Value = data(16, 22)
Cells(i, 4).Offset(0, 16).Value = data(4, 20) + data(6, 20)
Cells(i, 4).Offset(0, 17).Value = data(17, 22) + data(19, 22)
Cells(i, 4).Offset(0, 19).Value = data(7, 20)
Cells(i, 4).Offset(0, 20).Value = data(20, 22)
Else
If i = r Then
Cells(7, 4).End(xlDown).Offset(-2, 0).EntireRow.Insert
Else
End If
End If
Else
End If
Next i
End Sub