+ Reply to Thread
Results 1 to 6 of 6

Loop or use autofilter to get my results

  1. #1
    Forum Contributor
    Join Date
    10-31-2010
    Location
    london
    MS-Off Ver
    Excel 365
    Posts
    152

    Loop or use autofilter to get my results

    Hi all, just a quick question.

    I have a sheet that opens with a userform which has a textbox for you to imput your search criteria.

    I then want my code to look through three closed workbooks and everytime it finds my criteria copy that line and paste it onto my search sheet. my question is what would be the best way of achieving this. would I loop through every row and when I find it copy and paste or would I use the autofilter. the 3 closed workbooks would have around 100k rows of data each.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Loop or use autofilter to get my results

    Without doubt use autofilter. It is the fastest way I know to achieve what you want.

    As a general principle always use standard Excel functionality (if necessary in a macro) rather than writing looping code. There is a big time overhead with loops since each time through a loop VBA has to jump into Excel, do something and then jump back, all of which takes time. This can be mitigated somewhat by reading a range into a VBA array and processing the array before writing the answer back to Excel but stick with autofilter.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,791

    Re: Loop or use autofilter to get my results

    Autofilter would be the quickest way to get the data.

    Alf

  4. #4
    Forum Contributor
    Join Date
    10-31-2010
    Location
    london
    MS-Off Ver
    Excel 365
    Posts
    152

    Re: Loop or use autofilter to get my results

    Thanks Richard, that makes a lot of sense.

  5. #5
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Loop or use autofilter to get my results

    Hi bopsgtir,

    the "Loop" could end up with over 300k of rows, and it would be VERY SLOW.

    Rather go for autofilter if you can, and copy filtered Range.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  6. #6
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Loop or use autofilter to get my results

    O.K.,

    You other guys type much faster than me.

+ 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