View Single Post
 
Old 10-30-2017, 11:29 AM
FionaMcKenzie FionaMcKenzie is offline Windows 10 Office 2016
Novice
 
Join Date: Oct 2017
Location: Surrey, United Kingdom
Posts: 14
FionaMcKenzie is on a distinguished road
Default

Hi there,

With regards to this line of code have you considered using current region? If you use .End and there are gaps in your data ever it's not accurate. Whereas CurrentRegion is like clicking in a cell in a range and pressing Ctrl+Shift+* to work out the contiguous range even if there are gaps in any cells in the first column.

Rend = .Cells(.Rows.Count, "A").End(xlUp).Row

Change to:
Rend = .Range("A1").CurrentRegion.Rows.Count

Also seeing as you are reading so many lines of data from Excel, it may be quicker to make a SQL query using ADO.DB to get the data out of the source worksheet & output it to the destination worksheet. Once your SQL query is run, you do not need to loop through the recordset like you are through your worksheet.

If you write the correct SQL query you would get the result of your query, then you output the recordset result in one line of code,
e.g. oRange.CopyFromRecordset oADORecordSet - which would be quicker.

Kind regards
Reply With Quote