Copy filtered data from one workbook and paste data into another

db2020

New Member
Joined
Jun 6, 2021
Messages
21
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hi all,

I want to copy filtered data from one workbook and paste the data into another. The column that should be filtered is column Z, and it should be filtered on the value "Yes". Once the data is filtered, I want to copy the data in columns A - T (U-Z are formulas that I don't want to copy) into another workbook. Below is the code I am currently using:

VBA Code:
Sub Paste_Data()

Application.DisplayAlerts = False
Application.EnableEvents = False

Workbooks.Open "[File Location]"
Workbooks("[File Name].xlsx").Sheets("Sheet1").Range("A1:Z1").AutoFilter
Workbooks("[File Name].xlsx").Sheets("Sheet1").Range("A1:Z100000").AutoFilter Field:=26, Criterial:="Yes"
Workbooks("[File Name].xlsx").Sheets("Sheet1").Range("A1:T100000").SpecialCells(xlCellTypeVisible).Copy
ThisWorkbook.Sheets("[Tab Name]").Range("A2").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Workbooks("[File Name].xlsx").Close SaveChanges:=True

Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub

However, I get the following error:
1627488094067.png

Any idea how to solve this?

Best,
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,214,946
Messages
6,122,401
Members
449,081
Latest member
JAMES KECULAH

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