I have a code to load data from any number of workbooks we select and load in the current workbook. It works great in isolation (in a file where I dont perform any other tasks). However, when I used this code in a big file where I use(reference) the copied data in a number of array functions it takes over twenty minutes to load 1-2 files compared to seconds previously.
Is it possible its slow because of links to other tabs with functions? Am I missing something. Any help will be appreciated.
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.AskToUpdateLinks = False
Application.Calculation = xlCalculationManual
Number = 0
IT = 0
Set thisWb = ActiveWorkbook
Set ws = thisWb.Sheets("CF")
thisWb.Sheets("CF").Select
ws.Range(ws.Cells(2, 1), ws.Cells(100000, 42)).ClearContents
Do
files = Application.GetOpenFilename(filefilter:="Excel workbooks (*.csv*),*.csv*", Title:="Select files to import", MultiSelect:=True)
If Not IsArray(files) Then Exit Sub 'Cancel must have been clicked
If UBound(files) < 1 Then
MsgBox "You have not selected any file. Please select files."
End If
Loop Until UBound(files) > 0
Number = UBound(files)
N = Number + N
For IT = 1 To UBound(files)
Workbooks.Open files(IT)
With ActiveWorkbook
Application.CutCopyMode = False
Set wk = ActiveWorkbook.ActiveSheet
.ActiveSheet.Range("A2:AP10000").Copy
'LastRow = wk.Cells(Rows.Count, "A").End(xlUp).Row
thisWb.Activate
ws.Select
LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row + 1
Range("A" & LastRow).Select
Set Rng = ws.Range("A" & LastRow)
Rng.PasteSpecial xlPasteValues
LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row + 1
Application.CutCopyMode = False
.Close False
End With
Next
Anything that can make this code run faster like load 3-4 small files in a minute will be perfect.