+ Reply to Thread
Results 1 to 8 of 8

help with range.find method not finding search term

  1. #1
    Registered User
    Join Date
    07-18-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    36

    help with range.find method not finding search term

    I am trying to speed up the following function using the .find method rather than the original DO loop.
    I can't figure out why the str is not found by the .find method
    FYI, I have it set up to run both methods of finding the row number to determine if the new method always returns the same as the original method before I delete the original DO loop.

    Please Login or Register  to view this content.
    Thanks in advance.

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,267

    Re: help with range.find method not finding search term

    Both wersions of your code worked for me, but I would change

    Please Login or Register  to view this content.
    to, this, which picks up the absolute row instead of the row relative to the range (not an issue if the range starts in row 1.....)

    Please Login or Register  to view this content.
    And I would set the matchcase argument of the find method to false:

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    07-18-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    36

    Re: help with range.find method not finding search term

    Thanks Bernie,
    I was wondering if you threw a couple of timer statements in there if you find that the .find method is any quicker than my original routine. this routine is deep in some loops so I am really interested in getting every bit of performance as possible. I know that the STR will match case with the cell value, so I removed the UCASE. Based on another site, I have tried assigning the range to variant (array) and then looping through the variant array but had the same performance. Thanks for verifying the .find method works for you. Any possibility you might have an answer for my other two recent posts that have no responses?

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,267

    Re: help with range.find method not finding search term

    The find method will generally be quicker - how much quicker depends on the number of cells that your are searching. A couple? Or millions?

    As a first principle, I try to rely on built in features rather than looping code when dealing with cells: sorting, filtering, finding, removing duplicates, using formulas in a block, etc. There are a lot of good things hidden within Excel

    I looked at your other posts and have nothing to offer... sorry.

  5. #5
    Registered User
    Join Date
    07-18-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    36

    Re: help with range.find method not finding search term

    Thanks Bernie,
    I found my issue with my find method. the following single line always returns r2.row=1 even though I have ~10,000 rows of data and the first row with no data in column A is 9,943.
    Do you know the proper syntax to find the first row w/o data in the range? My range is a single column equivalent to "A1:A10000"

    Please Login or Register  to view this content.
    For reference the second half of routine:
    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,267

    Re: help with range.find method not finding search term

    It depends.

    If the cells can be truly blank, then you could use code like

    Please Login or Register  to view this content.
    If the cells have formulas that actually return "", then use code like (note the number of " characters! (six))

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    07-18-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    36

    Re: help with range.find method not finding search term

    The cells were set using code:
    Please Login or Register  to view this content.
    Which approach would I use?

  8. #8
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,267

    Re: help with range.find method not finding search term

    The specialcells line should find it. Your code has the same effect as clearing a cell

    range(row,col).ClearContents

+ 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] Best method for finding MAX value in a Range, ignoring non-numeric values
    By TC1980 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-03-2014, 08:47 AM
  2. Replies: 2
    Last Post: 03-17-2014, 04:19 PM
  3. Replies: 2
    Last Post: 06-29-2012, 06:32 AM
  4. Replies: 2
    Last Post: 06-24-2012, 02:55 PM
  5. Not finding value, range method failing
    By davegb in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-06-2006, 11:45 AM
  6. [SOLVED] Find method - finding multiple values
    By nathan in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-23-2005, 06:05 PM
  7. Refine search criteria for Find Method
    By ExcelMonkey in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-20-2005, 10: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