How to Speed Up Excel VBA When Copying Filtered Rows
Question details
The user needs to improve the execution speed of an Excel VBA macro that takes several minutes to copy and paste filtered rows from large worksheets.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Running a VBA macro to filter large datasets and copy only the visible rows to a destination worksheet.
- Observed behavior
- The VBA macro execution is extremely slow, sometimes taking several minutes to complete, particularly noticeable after a recent Office update.
Before modifying your VBA code, save a backup copy of your macro-enabled workbook (.xlsm). It is also highly recommended to check for the latest Microsoft Office updates, as sudden performance bugs are frequently resolved in subsequent patches.
Optimize VBA Code with Direct Object Referencing
Directly referencing workbook and worksheet objects instead of relying on Select, Selection, ActiveCell, or Activate methods can drastically improve macro execution speed.
Using the .Select or .Activate methods in VBA forces the application to physically update the user interface and move the active cursor. This process requires significant processing power, especially when handling large loops or datasets. Direct object referencing interacts purely with the data in the background, executing instantaneously.
Review your VBA code and delete any instances of .Select, .Selection, or .Activate. Instead, use 'With' statements to directly point to your source workbook, sheet, and table objects.
After applying your AutoFilter in the code, use the .SpecialCells(xlCellTypeVisible).Copy command to instruct Excel to copy only the filtered rows, ignoring hidden data.
Paste the copied data directly to the destination range using .PasteSpecial Paste:=xlPasteValuesAndNumberFormats to avoid copying unnecessary background formatting that can bloat the file.
Add 'Application.CutCopyMode = False' at the end of your macro to clear the clipboard and free up system memory.

Check for and Install Microsoft Office Updates
If the macro performance issue began suddenly after an update, installing the latest Office patch may resolve the underlying software bug.
Run Your VBA Macros Seamlessly with WPS Spreadsheet
WPS Office Spreadsheet provides excellent compatibility with Microsoft Excel VBA macros. By using WPS Office, you can execute complex macros, filter large datasets, and automate your workflow with high performance, avoiding slow execution times.
- 1. Download and install WPS Office: Download WPS Office from the official website and install it on your device. Open your macro-enabled workbook (.xlsm) using WPS Spreadsheet.
- 2. Access the Developer tab: Navigate to the 'Developer' tab on the top ribbon. If it is not visible, you can easily enable it from the WPS settings menu.
- 3. Run your optimized macro: Click on 'Macros', select your script for copying filtered rows, and click 'Run' to experience fast and efficient data processing.

Frequently Asked Questions
Why is the .Select method so slow in VBA?
The .Select and .Activate methods force the application to update the graphical user interface by physically moving the cursor and changing the active view. This screen updating process requires significant processing time, especially in loops, whereas direct object referencing interacts purely with the data in the background.
How does SpecialCells(xlCellTypeVisible) work in VBA?
This method targets only the cells that are currently visible on the worksheet, completely ignoring any hidden or filtered-out rows. It is a highly efficient way to copy filtered data without having to loop through every single row to check its visibility status.
Does WPS Office support Excel VBA macros?
Yes, WPS Office Spreadsheet supports VBA (Visual Basic for Applications). You can run, edit, and create macros just as you would in Microsoft Excel, providing a seamless and highly compatible automation experience.




