I would like to apply filter on a table on 1 field, then copy and paste the values to another workbook.I used a code below. But its not working.
Due to to big data the excel suddenly stops responding. How to change the code. Help me
sub createfilter()
Dim FiltRng As Range Dim RngArea As Range
Sheet2.ListObjects("DataTable").Range.AutoFilter Field:=12, Criteria1:="DE", Operator:=xlFilterValues
For Each RngArea In Sheet2.ListObjects("DataTable").Range.SpecialCells(xlCellTypeVisible).Rows
If RngArea.Row > 1 Then
If Not FiltRng Is Nothing Then
Set FiltRng = Application.Union(FiltRng, RngArea)
Else
Set FiltRng = RngArea
End If End If
Next RngArea
If Not FiltRng Is Nothing Then
FiltRng.Copy
Windows("Land-DE.xlsx").Activate
Sheets("Overall view").Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False End If
End sub
This doesn't use Copy and Paste (not the best way to transfer data) but should do what you want
You can also just copy the filtered range.
Only the non-filtered rows are copied by default:
Update with
PasteSpecial
(not tested) :