Speeding up code: takes 200 seconds to copy paste from one table to another using VBA!

Celticfc

Board Regular
Joined
Feb 28, 2016
Messages
153
Hi, I have a code which filters a table, copies the filtered data and puts it into another table as values but this process takes too long (170-200 seconds to be precise!). If I convert the table to a range then paste, it takes about 15 seconds but destroys all my formulas with reference to headers i.e. employee[location] to sheetname/column name etc.

Is there anything that I can do to speed up the process?

I would appreciate any support.

Thank you.

Code:
Code:
Sub ReceiveData()
Dim wb As Workbook
Dim t As Single
  
t = timer
Set wb = Workbooks("master.xlsb")
Set datatable = wb.Worksheets("alltemps").ListObjects("datatable")
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
   
 datatable.Range.AutoFilter Field:=2, Criteria:="temps"
    
 datatable.Range("A2:k3000").SpecialCells(xlCellTypeVisible).Copy
    
Calculate
    ThisWorkbook.Sheets("local").Range("A2:k3000").Clear
    ThisWorkbook.Sheets("local").Range("A2:k3000").PasteSpecial xlPasteValues
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic


MsgBox (Format(timer - t, "0.000 secs"))
End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Hi Celticfc,


You have covered all the good stuff, so I will ask:

Do you have any volatility in your formulas? The more you have of these the more time it will need to calculate at each itineration. Even though you do have calculation set to manual, it may be taking the time to calculate before the code gets to that line. I have a 63,000 record table, and it does take some time, but for 3,000 it might be something else.

Also, it maybe that the workbook may be corrupted, this used to happen in older version of Excel, but you don’t know until you investigate.
 
Upvote 0
Why do you have Calculate in the macro?

Have you tried stepping through to see what is taking a long time?
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,264
Members
452,627
Latest member
KitkatToby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top