This code produces an error when there is no file path in the import tab. Therefore, I included On Error Resume Next
in order to run the next loop. However, after On Error Resume Next
the code continues to run through the copy operation which messes up the tab I'm copying to.
I identified that the solution is that On Error the code should enter into the next loop instead of continuing the operation. Does anyone have any input on how to change the Error handling to do that?
Sub ImportBS()
Dim filePath As String
Dim SourceWb As Workbook
Dim TargetWb As Workbook
Dim Cell As Range
Dim i As Integer
Dim k As Integer
Dim Lastrow As Long
'SourceWb - Workbook were data is copied from
'TargetWb - Workbook were data is copied to and links are stored
Application.ScreenUpdating = False
Set TargetWb = Application.Workbooks("APC Refi Tracker.xlsb")
Lastrow = TargetWb.Sheets("Import").Range("F100").End(xlUp).Row - 6
For k = 1 To Lastrow
filePath = TargetWb.Sheets("Import").Range("F" & 6 + k).Value
Set SourceWb = Workbooks.Open(filePath)
On Error Resume Next
Range("A1").CurrentRegion.Copy
TargetWb.Sheets("Balance Sheet Drop").Range("D" & 2 + (k - 1) * 149).PasteSpecial Paste:=xlPasteValues
Range("A1").Copy
Application.CutCopyMode = False
SourceWb.Close
Next
Application.ScreenUpdating = True
Worksheets("Import").Activate
MsgBox "All done!"
End Sub