Excel 2007 Advanced Filter Painfully Slow

It 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.
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?

The 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! Turn off the screen updating — a simple solution. You’d think.
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? It didn’t seem likely, but as soon as I deleted the comment, the code ran perfectly. Put the comment back, and it 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.
AdvancedFilterSlow02
Then 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
I deleted the shape, and the code was still slow, and I had to delete the comment to speed it up again.

The Verdict

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.
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.
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, please watch this short Excel video tutorial.
Excel 2007 Advanced Filter Runs Very Slowly

____________