Hello see code below.
Sub RunAllMacros()
Dim wbSource As Workbook
Dim row As Integer, os As Integer
row = 2
os = 0
Do While Dir(Range("J" & row).Value) <> ""
Set wbSource = Workbooks.Open(Range("J" & row).Value)
With wbSource.Sheets("Work").Select
Range("A5:E500").Copy
Application.DisplayAlerts = False
wbSource.Close
Application.DisplayAlerts = True
If Range("A1").Value <> "" Then os = 1
Range("A" & Rows.Count).End(xlUp).offset(os).Select
ActiveSheet.Paste
End With
row = row + 1
Loop
Set wbSource = Nothing
End Sub
I have this code to loop through and copy other excel files from paths that are in J. It works great BUT it comes up at the end with a type mismatch. Not a big deal but kinda annoying. I think it has to do with the loop finding a blank cell in the next J field. Please let me know if you have a line of code to fix that error and stop the loop when no J is found. Thanks!
Sub RunAllMacros()
Dim wbSource As Workbook
Dim row As Integer, os As Integer
row = 2
os = 0
Do While Dir(Range("J" & row).Value) <> ""
Set wbSource = Workbooks.Open(Range("J" & row).Value)
With wbSource.Sheets("Work").Select
Range("A5:E500").Copy
Application.DisplayAlerts = False
wbSource.Close
Application.DisplayAlerts = True
If Range("A1").Value <> "" Then os = 1
Range("A" & Rows.Count).End(xlUp).offset(os).Select
ActiveSheet.Paste
End With
row = row + 1
Loop
Set wbSource = Nothing
End Sub
I have this code to loop through and copy other excel files from paths that are in J. It works great BUT it comes up at the end with a type mismatch. Not a big deal but kinda annoying. I think it has to do with the loop finding a blank cell in the next J field. Please let me know if you have a line of code to fix that error and stop the loop when no J is found. Thanks!