+ Reply to Thread
Results 1 to 12 of 12

Trouble with Find in VBA

  1. #1
    Registered User
    Join Date
    06-23-2012
    Location
    San Francisco, CA
    MS-Off Ver
    Excel 2007
    Posts
    47

    Trouble with Find in VBA

    I have this code that I have attempted to modify(obviously incorrectly) to search for a text string in a column and then delete any rows if that value is found. Currently I have it set to find a single text string "api", but I would like to add more text strings to it. It is not working properly as is and I was hoping someone would be willing to help me troubleshoot. The original code was written by Jbeaucaire. The code will select the range but then I'm receiving a run time 424 -object required error...

    Please Login or Register  to view this content.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Trouble with Find in VBA

    Try:

    Please Login or Register  to view this content.
    in place of:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    06-23-2012
    Location
    San Francisco, CA
    MS-Off Ver
    Excel 2007
    Posts
    47

    Re: Trouble with Find in VBA

    I'm still getting the run time error on the first line of code...



    I've attached a workbook.
    Attached Files Attached Files
    Last edited by Panda2000; 07-23-2012 at 08:24 PM.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Trouble with Find in VBA

    Hello Panda2000,

    What are you looking for in column "A"?
    Once the value is found, do you really want to delete that entire row?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Trouble with Find in VBA

    Hi Panda2000,

    This works but I'm not sure that it's what you wanted:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    06-23-2012
    Location
    San Francisco, CA
    MS-Off Ver
    Excel 2007
    Posts
    47

    Re: Trouble with Find in VBA

    Would it work to use boolean operators such as Or in the Let What = "API" portion of the code? There are several items for which I am searching; "api", "irrigation", and "gels". Ideally I would like to use the Instr function as there is sometimes variability in the text strings to some degree. Once these rows are found I'm sure that they are to be deleted.
    Last edited by Panda2000; 07-24-2012 at 12:23 PM.

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Trouble with Find in VBA

    I don't think that would work. But here's an interactive routine that lets you enter your search values individually and it's set to quit on a null entry:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    06-23-2012
    Location
    San Francisco, CA
    MS-Off Ver
    Excel 2007
    Posts
    47

    Re: Trouble with Find in VBA

    Would you know how to convert that "what" value into an Instr function? So if "irrigation" was contained in any part of a text string that would be found as a match and then the row deleted? Also, how would I modify the code to delete the entire row and not just the cell?

    I'm using this more as a learning experience, hence the many questions.
    Last edited by Panda2000; 07-24-2012 at 02:04 PM.

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Trouble with Find in VBA

    Hello Panda2000,

    Change the argument LookAt in the Find from xlWhole to xlPart.

  10. #10
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Trouble with Find in VBA

    Hi Panda2000,

    If you want to use InStr then we'd need to reprogram the routine without the Finder.

    But to delete the whole row:

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    06-23-2012
    Location
    San Francisco, CA
    MS-Off Ver
    Excel 2007
    Posts
    47

    Re: Trouble with Find in VBA

    Cool and thanks!

  12. #12
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Trouble with Find in VBA

    You're welcome!

+ 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