Hi, I'm currently using the code below to retrieve rows of data (based on date) from another workbook.
It works well but after using it for a year the rows of data that it has to search has blown out to 30,000 rows, which has made it very slow.
I'm not familiar with using arrays or even if it would help here but is there a quicker way to search and copy data from another workbook?
Sub GetData()
Dim FileName As String
Dim DestWB As Workbook
Dim lastrow As Long
Dim strdate As String
Dim DCell As Range
'Get Date to search for
strdate = ThisWorkbook.Sheets("Variables").Range("A4").Value
strdate = Format(strdate, "Short Date")
'Get Database Location
FileName = ThisWorkbook.Sheets("Variables").Range("A8").Value
'Open Database
Set DestWB = Workbooks.Open(FileName, ReadOnly:=True, notify:=False)
'Copy Data
ThisWorkbook.Worksheets("List").Rows("2:100000").ClearContents
lastrow = DestWB.Worksheets("Window1").Cells(Rows.Count, "D").End(xlUp).Row
For Each DCell In DestWB.Worksheets("Window1").Range("D2:D" & lastrow)
If CDate(DCell.Value) = strdate Then
DCell.EntireRow.Copy _
Destination:=ThisWorkbook.Worksheets("List").Cells(Rows.Count, "A").End(xlUp)(2)
End If
Next DCell
'Close Database
DestWB.Close SaveChanges:=False
Set DestWB = Nothing
End Sub
Thanks
Pete
Bookmarks