Hi All
I have a macro which does what I want it to, except that it seems to crash after around 14 files. (It used to run fine, and currently needs to complete about 70 files... though that list will grow)
Anyone have any suggestions on how i can improve my code to avoid the "Cannot Paste Data" error that I keep getting?
I have a macro which does what I want it to, except that it seems to crash after around 14 files. (It used to run fine, and currently needs to complete about 70 files... though that list will grow)
Anyone have any suggestions on how i can improve my code to avoid the "Cannot Paste Data" error that I keep getting?
VBA Code:
Option Explicit
Sub get_Skills_data()
Dim Wb1 As Workbook
Dim SourceRow As Long
Dim SourceCol As Long
Dim TargetRow As Long
Dim TargetCol As Long
Dim FileCell As Long
Dim LoopCounter As Integer
'variables defined above, then start points set below
SourceRow = 2
SourceCol = 3
TargetRow = 2
TargetCol = 1
LoopCounter = 0
Application.Calculation = xlManual
Application.DisplayAlerts = False
Worksheets("SKILLS DATA").Visible = True
ActiveWorkbook.Sheets("FileList").Select
Application.ScreenUpdating = False 'to stop flicker as macro works
Do Until IsEmpty(Cells(SourceRow, SourceCol))
Set Wb1 = Workbooks.Open(Cells(SourceRow, SourceCol).Value) 'opens the source data sheet
Wb1.Sheets("FLAT_FILE2").Range("A2:AB8").Copy
Wb1.Close SaveChanges:=False
ActiveWorkbook.Sheets("SKILLS DATA").Select
Cells(TargetRow, TargetCol).Select
ActiveSheet.Paste
Application.CutCopyMode = False 'added in recently to try to avoid crashes, but has not helped
TargetRow = TargetRow + 7
SourceRow = SourceRow + 1
LoopCounter = LoopCounter + 1
Application.StatusBar = LoopCounter & " files completed" 'shows progress through the macro
ActiveWorkbook.Sheets("FileList").Select
Loop
ActiveWorkbook.Sheets("03. Skills").Select
[A2].Value = Date + Time 'time-stamp last update
Application.StatusBar = False 'to clear the status bar again
Worksheets("SKILLS DATA").Visible = False
Worksheets("INSTRUCTIONS").Visible = False
MsgBox ("Data Refresh Complete: " & LoopCounter & " Files Copied. Recalculate?") 'to confirm completion of macro
Application.ScreenUpdating = True 'to turn back on normal operation
Application.DisplayAlerts = True '(not needed if not using above)
Application.Calculation = xlAutomatic
End Sub
Last edited by a moderator: