I am trying to move certain worksheets to a new workbook and copy paste all cells as values to remove formula's and links to other worksheets. The problem is my code is taking far too long (I have ID'd part of the code which is responsible for this). Any help in making this more efficient would be much appreciated.
Currently I am using the follow code to copy worksheets to a new workbook. The code is taking 48 seconds to run.
dim i as variant
i=array (I have a total of 10-12 worksheets named here)
thisworkbook.sheets(i).copy
The below code copies and paste the cells as values in the new workbook created. The code is taking approx 140 seconds to run (having checked with debug.print timer code)
activeworkbook.sheets.select
cells.select
selection.copy
selection.pastespecial paste:-xlpastevalues, operations:-xlnone, skipblanks
:=false, transpose:=false
I have also tried using the changing the code to use the below to paste values
dim ws as worksheet
for each ws in activeworkbook.worksheets
with ws.usedrange
.value = .value
end with
cells (1,1).select
net ws
The problem with this is it doesn't work with the worksheets that have a pivot table on them and throws up an error.
Thank you