+ Reply to Thread
Results 1 to 4 of 4

Speed of Range.Find vs Range.FindNext

  1. #1
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Speed of Range.Find vs Range.FindNext

    Hello all,

    I have been noticing the use of .FindNext more and more in recent code examples. I know that .FindNext looks a bit cleaner, but when I was learning VBA, I found that the .FindNext method was quite a bit slower (about 40% slower) than just using .Find over and over. I realize that seems a little counterintuitive, so I made a test workbook to verify if that was true or not.

    Attached is a zip file containing the test workbook (had to zip it to get it under the 1 MB limit, test file is 4.46 MB).
    The test file has 1 sheet with with just the word "text" in cells A1:E50000 (so 250,000 cells with just the word "text").
    The file has 2 macros to test the speed of the different methods. The macros are identical except for one uses only the .Find method while the other uses the .FindNext method.

    Find Only:
    Please Login or Register  to view this content.


    FindNext:
    Please Login or Register  to view this content.


    I ran each macro 3 times. Here were the results (in seconds)

    Find Only (Average 9.792969):
    10.015625
    9.671875
    9.69140625

    FindNext (Average 13.88151):
    13.89453125
    13.875
    13.875

    As a result, I have always solely used .Find instead of .FindNext. Is there any reason or advantage to use .FindNext other than the code "looks better"?

    [EDIT]
    Adding system specs for reference regarding code run speed (this is the system that ran the test):
    Windows XP Pro 2002 SP3
    Intel Core2 Duo 2.99 GHz
    3.49 GB of RAM
    Excel 2007 SP3
    Attached Files Attached Files
    Last edited by tigeravatar; 06-18-2012 at 12:47 PM. Reason: Added test machine's system specs
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Speed of Range.Find vs Range.FindNext

    on 2011 with a smaller dataset there is very little difference (259 v 260 seconds). of course you can't use findnext in a udf, so that's an advantage for multiple finds.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Speed of Range.Find vs Range.FindNext

    Thank you for the reply, JP. I was unaware that .FindNext didn't work in UDF's (becuase I've only ever used .Find), so that is good to know

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Speed of Range.Find vs Range.FindNext

    also you can't use findnext if you have another find inside the outer find, or if you want to search formatting.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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