+ Reply to Thread
Results 1 to 14 of 14

How to speed up a macro to filter data

  1. #1
    Registered User
    Join Date
    01-06-2013
    Location
    New York, EUA
    MS-Off Ver
    Excel 2013
    Posts
    77

    How to speed up a macro to filter data

    Hello everybody,

    In a workbook, called “Filter.xlsm”, half of the cells in Range(“A1:AL1048576”) is filled with data and the other half is blank. I run the following macro to filter this worksheet and to count the number of filered rows. It takes 20 seconds to complete one filtering cicle with 15 fields. It seems to be fast, but as I have to filter this worksheet 1000 times, this macro takes more than 5 days to be finished. Is there a way to speed this macro up? I have a quad-core processor (QX9770) and the CPU usage is stuck at 25%.

    Please Login or Register  to view this content.
    Any help would be appreciated.

    John
    Last edited by JOAO12; 08-22-2014 at 09:59 AM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: How to speed up a macro to filter data

    Have you really got over a million rows of data? And do all 1000 criteria ranges have numbers in them?

    Would you not be better taking each row in the criteria sheet and "building" a criteria range for an Advanced Filter rather than using AutoFilter criteria?

    Just some thoughts

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    01-06-2013
    Location
    New York, EUA
    MS-Off Ver
    Excel 2013
    Posts
    77

    Re: How to speed up a macro to filter data

    Hi TMS,

    Half of cells from Columns "A" to "AL" (workbook "Filter.xlsm") are filled with data and the other half are blank.

    Yes, all 1000 criteria ranges have numbers in them. They are needed to calculate the 15 fields used to filter workbook "Filter", by adding "13" to its value.

    In the advanced filter, can I determine that the 15 fields to be filtered are the values of the 15 cells in the criteria sheet added to the number "13" ?

    Regards,

    John

  4. #4
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: How to speed up a macro to filter data

    hi John, the speed issue you are facing is not linked to the computer power but to the approach being used. Can you post sample file data to play with? It would be also helpful to have expected result on the data provided.

  5. #5
    Registered User
    Join Date
    01-06-2013
    Location
    New York, EUA
    MS-Off Ver
    Excel 2013
    Posts
    77

    Re: How to speed up a macro to filter data

    Hi,

    In fact, all I need is to count the filtered rows of workbook "Filter.xlsm" using 15 fields.

    Each one of the 15 fields is determined by adding the number "13" to the corresponding cell value of range("C" & x & ":Q" & x), being x=1 to 1000 (workbooks "Criteria.xlsm").

    The code mentioned in the first post do this, but as I have to work with a big amount of data, it takes days to finish this macro.

    Feel free to change the macro. As I said before, my goal is to count the filtered rows of workbook "Filter.xlsm" using 15 fields.

    Thanks,

    John.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How to speed up a macro to filter data

    If you want to count based on criteria could you not use formulas, eg SUMPRODUCT?
    If posting code please use code tags, see here.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: How to speed up a macro to filter data

    Please Login or Register  to view this content.
    I would envisage the 15 fields being copied to an Advanced Filter Criteria range. So I don't see any problem adding 13 to each of them as part of the process.

    Regards, TMS

  8. #8
    Registered User
    Join Date
    01-06-2013
    Location
    New York, EUA
    MS-Off Ver
    Excel 2013
    Posts
    77

    Re: How to speed up a macro to filter data

    I am searching how to write an advanced filter code, but up to now I have no idea to do so.

    TMS, could you please change the autofilter code to the advancedfilter code?

    Thanks,

    John

  9. #9
    Registered User
    Join Date
    01-06-2013
    Location
    New York, EUA
    MS-Off Ver
    Excel 2013
    Posts
    77

    Re: How to speed up a macro to filter data

    Hi TMS,

    I am posting two sample files: Filter.xlsm and Field.xlsm.

    Field.xlsm has the column "C" up to "Q" filled with numbers. These numbers will be added to 13, in order to calculate each one of the 15 fields of the workbook Filter.xlsm that will be filtered. Note that the filtering criteria is that the cell be blank.

    Any help in making this macro faster would be appreciated.

    Regards,

    John
    Attached Files Attached Files
    Last edited by JOAO12; 08-22-2014 at 02:09 PM.

  10. #10
    Registered User
    Join Date
    01-06-2013
    Location
    New York, EUA
    MS-Off Ver
    Excel 2013
    Posts
    77

    Re: How to speed up a macro to filter data

    Hi watersev,

    I have uploaded two sample files.

    Any help would be appreciated.

    Regards,

    John

  11. #11
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: How to speed up a macro to filter data

    hi John, please check attachment, Field and Filter data are joined in one workbook. Press "Run" button or run code "test".
    Attached Files Attached Files

  12. #12
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: How to speed up a macro to filter data

    hi John, please check attachment. This would eliminate duplicate rows from results.
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    01-06-2013
    Location
    New York, EUA
    MS-Off Ver
    Excel 2013
    Posts
    77

    Re: How to speed up a macro to filter data

    Hi Watersev,

    Your macro works perfectly. Thank you very much for your efforts on helping me with this macro. You did an excellent job.

    John

  14. #14
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: How to speed up a macro to filter data

    hi John, another option, please check if it does what you want and its time of execution. Press Run button on Filter sheet or run code "test1"
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Speed up macro for copying data from another workbook
    By greengirl in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-13-2014, 12:18 PM
  2. [SOLVED] Macro for transfering data, Help with improvement of speed
    By 2001jesper in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-29-2013, 07:49 AM
  3. [SOLVED] How to speed up deleting duplicates using a filter
    By fredlo2010 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-13-2013, 09:20 PM
  4. Speed Up Automated Pivot Filter
    By AarEck in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-02-2012, 01:17 PM
  5. Replies: 1
    Last Post: 04-02-2011, 06:39 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1