+ Reply to Thread
Results 1 to 12 of 12

How to code the selection.find not to crash when the data to find is blank

  1. #1
    Forum Contributor
    Join Date
    02-12-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2007
    Posts
    275

    How to code the selection.find not to crash when the data to find is blank

    Hi all

    What must the coding be not to recieve the "runtime error 91" when the value to find is not to be found.

    The value is spesified in a cell and in vba stored in a register (dim value as string). As long as the value exist in the search range it works but as soon as the value is not present i get the error.

    The (on error goto...) works but I would like to avoid the error from the start.
    Last edited by evertjvr; 05-23-2012 at 08:24 AM. Reason: Unable to open a thread on the PC and unable to unmark the Solved on the tablet.

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

    Re: How to code the selection.find not to crash when the data to find is blank

    you need to test the result of the find before you try and do anything with it (check if it is Nothing). if you post your code I can show you in detail.
    Josie

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

  3. #3
    Forum Contributor
    Join Date
    02-12-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2007
    Posts
    275

    Re: How to code the selection.find not to crash when the data to find is blank

    Sorry I had to run

    Here is the file with the basic code

    The aim is to prevent the error instead of redirecting in case of error.

    Thanks

    Test 1.xlsm

  4. #4
    Forum Contributor
    Join Date
    02-07-2012
    Location
    MIA
    MS-Off Ver
    Excel 2007, 2010
    Posts
    429

    Re: How to code the selection.find not to crash when the data to find is blank

    I think this should work:

    Please Login or Register  to view this content.
    .?*??)
    `?.???.?*??)?.?*?)
    (?.?? (?.?
    Pichingualas <---
    ??????????????????????????

    Wrap your code with CODE TAGS.
    Thank those who helped you, Don't forget to add to their REPUTATION!!! (click on the star below their post).
    Please mark your threads as [SOLVED] when they are (Thread Tools->Mark thread as Solved).

  5. #5
    Forum Contributor
    Join Date
    02-07-2012
    Location
    MIA
    MS-Off Ver
    Excel 2007, 2010
    Posts
    429

    Re: How to code the selection.find not to crash when the data to find is blank

    A slight change to make it better:

    Please Login or Register  to view this content.

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

    Re: How to code the selection.find not to crash when the data to find is blank

    no need for the goto really
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    02-07-2012
    Location
    MIA
    MS-Off Ver
    Excel 2007, 2010
    Posts
    429

    Re: How to code the selection.find not to crash when the data to find is blank

    By the way, if you are searching for values then you should change your code like this:

    Please Login or Register  to view this content.
    If you don't comment the line GoTo error marked in blue then your macro will never run through the lines in red. The change I was suggesting I marked in green, which you should do if looking at values instead of formulas...
    Last edited by Pichingualas; 05-23-2012 at 04:24 PM.

  8. #8
    Registered User
    Join Date
    09-15-2011
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    82

    Re: How to code the selection.find not to crash when the data to find is blank

    Hi all

    I was looking for something similar to this, with one exception, I needed to be able to search 3 sheets instead of one, and with columns A to H. How would the code be changed to do this ?

    Hope you can help with this

    Ortz

  9. #9
    Registered User
    Join Date
    09-15-2011
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    82

    Re: How to code the selection.find not to crash when the data to find is blank

    Hi all

    I was looking for something similar to this, with one exception, I needed to be able to search 3 sheets instead of one, and with columns A to H. How would the code be changed to do this ?

    Hope you can help with this

    Ortz

  10. #10
    Forum Contributor
    Join Date
    02-12-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2007
    Posts
    275

    Re: How to code the selection.find not to crash when the data to find is blank

    Hi Ortz

    I have the answer to that one for you.

    This one still depend on the on error goto error line

    No this is not my coding but it works and thanks to the guy that helped me
    (I don't even know his name).

    test 1a.xlsm

  11. #11
    Forum Contributor
    Join Date
    02-12-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2007
    Posts
    275

    Re: How to code the selection.find not to crash when the data to find is blank

    Thanks Joseph P

    Your coding works like a charm and I can work with that (don't expect to recognize it when I'm done though)

    Thanks to Pichingualas too

  12. #12
    Registered User
    Join Date
    09-15-2011
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    82

    Re: How to code the selection.find not to crash when the data to find is blank

    Hi evertjvr

    Thats good

    However it only takes you to the 1st instance of the value it finds across all sheets. Is it possible for it to return all values it finds and allows you to go to your selected value ?

    Ortz

+ 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