Excel Advanced Filter Painfully Slow

Today, working on my Excel file was like riding a lazy snail through molasses in January — but slower!

Usually an Excel Advanced Filter is a speedy way to extract data from a table, but things weren’t working right in a sample file that I got last week.

And despite what my high school English teachers might think, you can’t mix too many similes, when trying to describe excruciating slowness.

Advanced Filter Macro Problem

The sample file had code that ran an Advanced Filter in Excel 2007.

The code ran quickly in Excel 2003, but screeched to a near halt in Excel 2007. What was the problem?

In the sections below, I detailed all the things I tried, while troubleshooting the slow macro problem.

  • Tip: You can skip to the end, to see what the unexpected problem was, and how I finally fixed the Advanced Filter macro.

There’s a video at the end of this post too, where I show the problem and the solution.

The Slow Filter Symptoms

When the code ran in Excel 2007, it looked like the extracted rows were being pasted in the second worksheet, one row at a time.

Aha! I should turn off the screen updating — a simple solution. You’d think.

Nope! Even with the screen updating turned off, the code barely crawled along.

It took almost 3 minutes to extract 1500 rows — maybe a millisecond faster than it ran with screen updating turned on. Who has that kind of time?

Guess Again

In the next round of solution guessing, I got rid of the few formulas in the worksheet and criteria range.

There wasn’t anything too complex, but maybe that was slowing things down.

I also changed calculation to manual at the start of the code, then set it to automatic at the end of the code.

Neither of those changes had any effect on the code’s speed.

Strip the Data Clean

In round 12 of testing (I’ve lost track of the test count), I copied the data, and pasted it as values into a new workbook.

The code ran like lightning. In July. With jet engines. Hmmm.

Maybe it was the formatting and styles in the original file that were slowing things down.

To test that theory, I formatted the original table with Normal style, which removed all the borders and fill colour.

That didn’t improve things, but when I removed the red fill from the heading cells, I noticed a red comment marker in one of the cells.

Whip Things Into Shape

Could a comment be the problem? That didn’t seem likely, but:

  • As soon as I deleted the comment, the code ran perfectly.
  • When I put the comment back, the macro slowed to a crawl again.

AdvancedFilterSlow01

Curiouser and Curiouser

When I tried to create a sample file to demonstrate this problem, things got even stranger.

I created a table with a comment in the heading, and ran the code, expecting it to be slow. It ran quickly, in several tests.

Timing the Advanced Filter Macro
Timing the Advanced Filter Macro

Add Shape to Worksheet

Next, I added a shape to the worksheet, and assigned a macro, to make it easier to run the code.

The code slowed down again!

AdvancedFilterSlow03

Next, I deleted the shape, and the code was still slow, so I had to delete the comment to speed it up again.

The Verdict on Slow Advanced Filter Macro

If your Advanced Filters are running slowly in Excel 2007, try removing any comments in the table heading cells.

You could delete them at the start of a VBA procedure, run the filter, then add the comments at the end of the code.

Shapes + Comments = Trouble

The problem seems to occur if there are heading comments, and a shape is added later, as you can see in the short video demonstration below.

Fortunately, this problem appears to be fixed in Excel 2010, so if you upgrade, you should be able to have comments and shapes, without slowing down the Advanced Filters.

Another Solution

Update: In the comments, PDLobster suggests the following solution, to speed up the filters — thanks!

  1. Turn off all filters
  2. Select cell A1
  3. Turn Wrap Text ON
  4. Select the entire worksheet
  5. Turn Wrap Text OFF

Watch the Video

To see the steps for reproducing and solving the Advanced Filter speed problem, you can watch this short Excel video.

____________

22 thoughts on “Excel Advanced Filter Painfully Slow”

  1. I’ve had this problem in 07 a few times before. Almost always, it was the result of ‘noise’ in the data and was correct by copy/paste special/values.

    The worst performance I’ve ever had during filtering though, was because there was that grouping feature turned on elsewhere in the sheet. Not like I’d ever use the grouping feature though…..

  2. Thank you! This was very helpful. In my case, I had 2 buttons located in the header rows of the data that I was extracting from – I removed these and the filtering FLIES!

  3. Here’s what worked for me in Excel 2007, regardless of code or conditional formats or comments:
    Turn off all filters
    Select cell A1
    Turn Wrap Text ON
    Select the entire worksheet
    Turn Wrap Text OFF

    that’s it!

  4. Had the same symptoms in my 2010 workbook: painfully slow advanced filter. Found your post, removed my comment, and it´s now much faster! Thanks for the info.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.