+ Reply to Thread
Results 1 to 14 of 14

Requesting critique on macro which copy filtered data to new table. = ) Workbook inside.

  1. #1
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Requesting critique on macro which copy filtered data to new table. = ) Workbook inside.

    Hi all,

    My basic problem is this: I often filter data and am then interested in compiling statistics or other stuff on this data. This can't be done using ordinary Excel formulas. So, my approach have been copy and paste filtered data to a new sheet. This is time consuming.

    With some online sample code, I was able to create a macro which copies my filtered data to a new similar table.

    Further, using the Macro Recorder, I was also able to create a macro which deletes the filtered data as the macro above does not clear the table first. I can live with that.

    Can I ask some of you guys kindly to take a look and see if this seems okay/correct? Or if there's something that could be done better?

    I made a few tests already and it does seem to work correcly.

    Thanks in advance!

    Best regards.

    Elijah
    Attached Files Attached Files

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Requesting critique on macro which copy filtered data to new table. = ) Workbook insid

    When dealing with tables. It is easier to refer to ListObject.

    Since each sheet has only one table. It can be quickly referenced using Sheets("SheetName").ListObjects(1)

    Also, when copying filtered range. It's easier to copy visible cells of range than to loop each row.

    Something like below as sample.
    Please Login or Register  to view this content.
    But to control filtering and extraction, it may be beneficial to use Advanced Filter Copy method. See link for detail.
    https://www.contextures.com/exceladvancedfiltervba.html
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Requesting critique on macro which copy filtered data to new table. = ) Workbook insid

    Hi, CK76,

    Great improvement! Now I only copy the visible cells as you said.

    Much better, I think. Thanks a lot.

    But to control filtering and extraction, it may be beneficial to use Advanced Filter Copy method. See link for detail.
    https://www.contextures.com/exceladvancedfiltervba.html


    My filtering is typically 'dynamic' and not predetermined.

    What's described there seemed more relevant if the filtering was decided in advance, i.e., pre-determined?

    Best regards and thanks.

    Elijah

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Requesting critique on macro which copy filtered data to new table. = ) Workbook insid

    You are welcome and thanks for the rep

    Advanced filter criteria range can be set up with dropdown etc to change criteria on the fly.
    For instance, advanced filter can use AND/OR condition combination on multiple columns, where autofilter isn't able.

    However, if there is need to visually scan available filter options, then it's better to stick with autofilter.

  5. #5
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Requesting critique on macro which copy filtered data to new table. = ) Workbook insid

    Quote Originally Posted by CK76 View Post
    You are welcome and thanks for the rep

    Advanced filter criteria range can be set up with dropdown etc to change criteria on the fly.
    For instance, advanced filter can use AND/OR condition combination on multiple columns, where autofilter isn't able.

    However, if there is need to visually scan available filter options, then it's better to stick with autofilter.
    Thanks, CK76.

    I will read up on those advanced filters. I'm sure I can find them beneficial in some way. I'm learning new things about this amazing software every day.

    Have a good weekend and thanks again!

  6. #6
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Requesting critique on macro which copy filtered data to new table. = ) Workbook insid

    Hello again,

    I'm now testing this macro on my bigger worksheet and it is a bit slow. I think this can be solved by limiting the amount of columns being copied.

    Let's first try with columns A to AV instead of the entire table. That would be A7:AV.

    How can that be done with this macro?

    I'm trying various List Objects references now, but haven't quite gotten it yet.

    Thanks in advance.
    Last edited by Elijah; 01-19-2019 at 02:25 PM.

  7. #7
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Requesting critique on macro which copy filtered data to new table. = ) Workbook insid

    It seems like it was as easy as updating

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.
    Putting it back as solved now.

    Have a good Sunday everyone.

  8. #8
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Requesting critique on macro which copy filtered data to new table. = ) Workbook insid

    Although I did put this as solved, I am noticing that it is very slow when copying large amounts of data.

    That's A:AV with roughly 1500 rows.

    Are there any ways to speed up this process or will things simply be slow when the dataset is as large as this...?

    I replaced Sheets("Data") with ActiveWorkbook.ActiveSheet in order to use the macro on all desired sheets without having to name the sheet.

    I wouldn't imagine that to make a difference.

    Thanks in advance.

  9. #9
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,483

    Re: Requesting critique on macro which copy filtered data to new table. = ) Workbook insid

    How does the new macro compare to your original macro? is it faster or slower?

    Copy pasting only visible rows can become slow because your copy range is split up into a new copy and paste range every time a row is hidden so if every 3 rows 1 row is hidden
    copy paste will do 1500/4 = 325 copy and paste actions. that makes it slow.


    If possible sorting the data so there is one continues range can help inprove copy/paste speed.

  10. #10
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Requesting critique on macro which copy filtered data to new table. = ) Workbook insid

    One way is to load range to variant array and write back to range. This is typically one of the fastest method.

    Another is advanced filter, which will require criteria range set up, but will be faster than autofilter method.

    These are two methods I typically use.

    Ex: Using array and collection...
    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Requesting critique on macro which copy filtered data to new table. = ) Workbook insid

    Wow, CK76!

    That was amazing and made a HUGE difference. I could copy my entire unfiltered table in about 1 second or less. For filtered data (100-500 rows) in the blink of an eye.

    Thanks again for all help! Really appreciated.

    Have a nice day!

    Best regards,

    Elijah

  12. #12
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Requesting critique on macro which copy filtered data to new table. = ) Workbook insid

    Quote Originally Posted by CK76 View Post
    One way is to load range to variant array and write back to range. This is typically one of the fastest method.

    Another is advanced filter, which will require criteria range set up, but will be faster than autofilter method.

    These are two methods I typically use.

    Ex: Using array and collection...
    Please Login or Register  to view this content.
    Hi, CK76,

    This macro have been very useful to me.

    Can it be modified to work between workbooks? Where Workbook 1 is a normal macro-activated workbook and Workbook 2 is a *.csv file?

    Thanks very much in advance.

    Elijah

  13. #13
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Requesting critique on macro which copy filtered data to new table. = ) Workbook insid

    If not, I will probably try to set up a dynamic link between sheet 2 (copied filtered data) and the *.csv file using PowerQuery.

  14. #14
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Requesting critique on macro which copy filtered data to new table. = ) Workbook insid

    I was able to handle this on my own, so no worries.

+ 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. Macro to Copy and paste filtered data to new workbook
    By walsha23 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-27-2018, 01:44 PM
  2. Macro that copy all data inside a workbook and paste in value in another document
    By elpoil in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-10-2013, 10:07 AM
  3. Copy filtered data into another workbook.
    By creusemeninge in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-25-2013, 05:00 AM
  4. requesting critique of my retirement spreadsheet
    By karlpilkington in forum Excel General
    Replies: 3
    Last Post: 09-22-2012, 02:38 PM
  5. Help macro copy filtered data to new workbook
    By alexoid in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-02-2011, 09:16 PM
  6. Copy Filtered Data from 1 workbook to another
    By mhuddles1981 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-26-2010, 11:38 PM
  7. [SOLVED] Macro to copy filtered list to new workbook.
    By cribology - ExcelForums.com in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-03-2005, 06:05 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