Reputation: 1
I have an excel tool that uses feed from 11 different raw data files generated from reporting system to do some calculations on that data.
The process is very simple: - open file - filter contents - copy filtered contents - paste into another file (the summary tool's tab)
As the amounts of data and individual files rose I started getting more issues with memory.Hence my question - what is the most memory and speed efficient way to copy/paste these tables?
(...).SpecialCells(xlCellTypeVisible).Copy Destination:=(...) - I haven't found the way to include XLValues parameter for this (I want to minimise the resources taken up by copying formatting, there are no formulas)
using defined ranges for the copy/paste purpose (name range with xlCellTypeVisible parameter, converting to another range to get the values only and sending the range to destination) - that would require additional variables for the ranges
plain old Columns(...).SpecialCells(xlCellTypeVisible).Copy and Range.("A1").PasteSpecial Paste:=xlValues - this method has both "only visible cells" and "paste values only" bits that I'm looking for, but it uses the clipboard as a middleman and I guess this is eating up my memory
Maybe there is yet another method that I don't know of?
Appreciate any insights!
Upvotes: 0
Views: 3010
Reputation: 96771
Fortunately there is a built-in feature for Autofilter to facilitate this. Say we start with:
and apply a filter to it with:
Sub Macro1()
Columns("A:B").AutoFilter
ActiveSheet.Range("$A$1:$B$8").AutoFilter Field:=2, Criteria1:=">50", Operator:=xlAnd
End Sub
==> The Autofilter has a Range
property that allows: <==
Sub Kopy()
Dim rng As Range
Set rng = ActiveSheet.AutoFilter.Range
rng.Copy Sheets("Sheet2").Range("A1")
End Sub
The result on Sheet2
has
Sheet1
NOTE:
Looping is not required.
Similar approach can be used for Tables
.
SpecialCells is not required.
Upvotes: 1