+ Reply to Thread
Results 1 to 7 of 7

not sure why find is finding nothing when it should

  1. #1
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,293

    not sure why find is finding nothing when it should

    so im searching the current workbook and worksheet (but i eventually want to search the whole folder) for a text string ("this is a test") found in cell A20. here is my code snippet:

    Please Login or Register  to view this content.
    what am i not understanding on how to use the find command?

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    XL 2010,2016
    Posts
    11,897

    Re: not sure why find is finding nothing when it should

    From what it looks like, you have the code searching A20 for the string "this is a test" and only A20. You need a bigger range if you want to search a bigger range.

  3. #3
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,293

    Re: not sure why find is finding nothing when it should

    actually that is by design. i have three area's that i MIGHT want to search for. the description (only cell A20), the item (cells B23 - B39) and the item description (cells E23 - E39). so here is the whole code so you can see.

    Please Login or Register  to view this content.
    so first question is how to search just one cell. second is how to search through a range of cells. how can this be fixed?

  4. #4
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,293

    Re: not sure why find is finding nothing when it should

    any help with the find command?

  5. #5
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    UK
    MS-Off Ver
    2010 primarily
    Posts
    3,264

    Re: not sure why find is finding nothing when it should

    You could just use Countif for this. Your code currently makes no sense as it just loops infinitely if you find the value.
    Rory
    Days when we raged, we flew off the page
    Such damage was done

  6. #6
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    10,492

    Re: not sure why find is finding nothing when it should

    Please Login or Register  to view this content.


    Range.Find is looking for an unknown cell with a particular value among multiple cells. A20 is a single known cell and you want to examine its contents...


    Set c = .Find("this is a test", after:=rng, LookIn:=xlValues)
    Debug.Print "made it to here 1"

    If Not c Is Nothing Then
    'c' starts off as Nothing/empty. When the search parm is found, it is no longer Nothing so now "NOT" c is nothing
    Last edited by protonLeah; 04-02-2019 at 07:40 PM.
    Ben Van Johnson

  7. #7
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,293

    Re: not sure why find is finding nothing when it should

    thanks @protonLeah, that got me over the hump. here is my finished code, working good.

    Please Login or Register  to view this content.
    what do you think.

+ 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