简体   繁体   中英

Excel Advanced Filter Very slow to run, but only after autofilter has been run

I have a very difficult issue I have been trying to solve for a few days, I would very much appreciate some help as I have tried to research this issue completely already. One one sheet I have a database (18 columns and 72,000 rows) in 32 Bit Excel 2010, so its a large database. On this sheet I also have some entries to auto-filter some columns, as well as an advance filter. When I run the Advanced filter, the data filters in 1 second exactly. If I run an auto-filter, (via vba macros) then run advance filter afterwords, the Advanced filter takes 60 seconds to run, even after turning autofiltermode to false. Here is what i have tried but no luck

  • Removing all shapes on the sheet
  • THere are no comments on the sheet so none to removed
  • Removing all regular and conditional formatting
  • Turning off auto-filter mode
  • Setting all cell text on the sheet to WrappedText = False
  • Un-protecting the sheet
  • Un-hiding any rows and columns
  • Removing any sorting (.sort.sortfields.clear)

What else could cause this code to run 60 times slower but only after autofilter has previously run on the sheet, and how can i return it to that state? Any and all help would be greatly appreciated

In my case I was programmatically creating named ranges for later use, and these named ranges used the .End(xlDown) functionality to find the end of the data set. For eg:

Set DLPRange = .Range(.Cells(2, indexHeaders(2)), .Cells(i, indexHeaders(2)).End(xlDown))
DLPRange.Name = "DLPRangeName"

... which creates a column range from the starting cell to the end of the document in my case. Originally this 'bad' way of finding the range went unnoticed because the file format of the workbook was .xls and maxed out at 65k rows. When I needed more I forced it to create a workbook in .xlsm format, which has ~1M rows. The filter ran on the whole column even though the huge majority of it was empty, resulting in the huge time overhead.

tl;dr: you've tricked excel into thinking it has a huge amount of data to filter. Untrick it by checking and making sure it's only filtering the range you think it should be filtering.

After trial and mostly lots of error I was able to find a solution. I determined that almost any action, even without auto-filter would cause this slowdown, and I felt that simply this was a memory issue for Excel with all of that data (even though it ran find sometimes, the 'cache' I'm guessing would fill up and then run slow. So what I did was use a new and temporary workbook in which the Advanced filter would add the data on filter. I then took this data and copied a portion of it back into my workbook. Then I closed this temporary workbook without saving it. This also brought the code run from 1 second to .3 seconds and I never got the slow Advanced filter run time, regardless of what code I ran or what I did on the original workbook. I posted this so if anyone else had a similar issue they might use this as a solution for large amounts of data.

A little late, but recently I had the same issue with a not so large database (4000+ rows, 70 columns) and solved it, so just sharing. In my case, problem was with wrapped text in data range. Setting WrappedText to false as you said helps is not enough, you need to replace Chr(10) in the range you are filtering. Huge difference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM