+ Reply to Thread
Results 1 to 13 of 13

Which would you prefer?

Hybrid View

  1. #1
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Which would you prefer?

    Hey All,

    While i was replying to so many VBA related threads, a question struck me and i couldnt decide which was better among the two. I thought of putting forth this question to all of you so you can provide your opinion.

    If you receive a question wherein the user would like to transfer the contents from one master sheet to several other sheets, split by for eg. month / date. Would you choose to use the autofilter method (get the list of unique dates and then filter by each date and copy to the respective tab) or would you go row by row through a loop and then copy the row to the appropriate tab?

    While running the code, which is more efficient and faster? Is it the autofilter or the row by row method?

    Need your inputs.

    Thanks everyone....have a nice day !!!
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Which would you prefer?

    Hi arlu1201

    The filter would be faster .. But if you are writing the code its your call . No right or wrongs just is.

    all loops are slow
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    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
    48,420

    Re: Which would you prefer?

    I'd choose the filter approach, though I think would be an Advanced filter rather than Autofilter.

    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


  4. #4
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Which would you prefer?

    Autofilter is more efficient to my knowledge. The only problem you can have is if the filtered data results in a range reference that is too complex to copy.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  5. #5
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Which would you prefer?

    I couldnt decide which was better among the two
    There are probably more methods to get the same results:

    - a databasequery
    - putting the data into an array, filter that in memory and writing the results to separate worksheets

    If you post a sample file we all can do some testing and compare the results.



  6. #6
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Which would you prefer?

    Quote Originally Posted by snb View Post
    There are probably more methods to get the same results:

    - a databasequery
    - putting the data into an array, filter that in memory and writing the results to separate worksheets.
    Or a filtered disconnected recordset?

  7. #7
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Which would you prefer?

    What is a filtered disconnected recordset?

  8. #8
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Which would you prefer?

    Have a look over here.

  9. #9
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Which would you prefer?

    or better, look here

  10. #10
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Which would you prefer?

    I've come across using disconnected recordsets before in a VBA book I skimmed through and they seem like they should be really useful, unfortunately I've never come a situation where they would actually be useful :s

    Plus I don't know of a way of filling them without looping (or memory leaks) which has always put me off.

    Maybe this is their calling - lots of filtering and finding on a dataset! They do look as though they would be much faster than filtering in Excel

  11. #11
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Which would you prefer?

    I'd suspect arrays would be faster than filters.
    Good luck.

  12. #12
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Which would you prefer?

    Quote Originally Posted by OnErrorGoto0 View Post
    I'd suspect arrays would be faster than filters.
    Is that based upon any evidence or your gut feeling?

  13. #13
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Which would you prefer?

    A little of both. I have seen similar questions where arrays have proven faster especially with large datasets. Here I think you would need to preprocess the data to get a list of dates to filter by and if you're going to iterate them anyway, I suspect it would be faster to do the work as you go (not copying row by row obviously!).
    However, unless speed were critical I would probably actually use the autofilter method for simplicity.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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