I am using this code to copy all the data from a sheet in the closed workbook to destination workbook. However this code loops through each cell and since the source workbook contains 40,000 rows, its taking too long. What changes can be made to this code to copy all the data from source worksheet to a specific worksheet in the destination workbook without looping through cells or if there is an alternative solution that you can provide.Thanks for your help
Sub GetDataDemo()
Dim FilePath$, Row&, Column&, Address$
Const FileName$ = "Book1.xls"
Const SheetName$ = "Sheet1"
Const NumRows& = 40000
Const NumColumns& = 10
FilePath = ActiveWorkbook.Path & "\"
'***************************************
DoEvents
Application.ScreenUpdating = False
If Dir(FilePath & FileName) = Empty Then
MsgBox "The file " & FileName & " was not found", , "File Doesn't Exist"
Exit Sub
End If
For Row = 1 To NumRows
For Column = 1 To NumColumns
Address = Cells(Row, Column).Address
dest. Cells(Row, Column) = GetData(FilePath, FileName, SheetName, Address)
Columns.AutoFit
Next Column
Next Row
ActiveWindow.DisplayZeros = False
End Sub
Private Function GetData(Path, File, Sheet, Address)
Dim Data$
Data = "'" & Path & "[" & File & "]" & Sheet & "'!" & _
Range(Address).Range("A1").Address(, , xlR1C1)
GetData = ExecuteExcel4Macro(Data)
End Function
Range
without usingExecuteExcel4Macro
. – L42