+ Reply to Thread
Results 1 to 8 of 8

".Find" Returns Run-time error '91': if the Item Is Not Found.

  1. #1
    Registered User
    Join Date
    12-21-2017
    Location
    Wokingham, England
    MS-Off Ver
    office 365 2013
    Posts
    46

    ".Find" Returns Run-time error '91': if the Item Is Not Found.

    I am trying to establish whether or not a Bank Holiday date appears on a list so I can use Workday_Intl to obtain the date of the previous working day.

    I am using the code line
    Please Login or Register  to view this content.
    which works fine when the search date is on the list but displays Run-time error '91': if it is not. I have to say this must take the award for being the most obscure, meaningless, and misleading error message of all time.

    What use is .Find if it cannot be used to find whether or not something is present?

    I have attached an example spreadsheet demonstrating the problem.

    Any help will be much appreciated.
    Tegglet
    Attached Files Attached Files
    Last edited by Tegglet; 10-28-2021 at 07:25 AM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,758

    Re: ".Find" Returns Run-time error '91': if the Item Is Not Found.

    Use a Range instead of a Long. If the holiday is not found, then the Range will be Nothing. Make the changes to your code as shown in red:

    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: ".Find" Returns Run-time error '91': if the Item Is Not Found.

    All you have to do is to trap your error.


    Please Login or Register  to view this content.

    Please Login or Register  to view this content.
    Last edited by mehmetcik; 10-28-2021 at 08:13 AM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,758

    Re: ".Find" Returns Run-time error '91': if the Item Is Not Found.

    It seems to me that there might be an easier solution than hard-coding a date and searching for it, since it seems that this would need to be variable. But I don't quite get what your ultimate goal is.

  5. #5
    Registered User
    Join Date
    12-21-2017
    Location
    Wokingham, England
    MS-Off Ver
    office 365 2013
    Posts
    46

    Re: ".Find" Returns Run-time error '91': if the Item Is Not Found.

    Hi mehmetcik,

    Many thanks for your prompt response. I am not sure what you mean by the following though:

    My Rules if you want my help:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.
    I was not aware that I had made any demands and this was a new post.

    Is it part of a general signature? If so it seems a bit harsh.

    regarding your suggestion, in the past I have not had a lot of luck with "On Error" statements and so have tended to avoid them. I will certainly try your suggestion though. I have to say it seems a bit of a weird way to have to do it when it is not really an error, just part of the process.

    Regards,
    Tegglet

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,758

    Re: ".Find" Returns Run-time error '91': if the Item Is Not Found.

    Quote Originally Posted by Tegglet View Post
    Is it part of a general signature? If so it seems a bit harsh.
    It is his signature, so appears in every thread he posts in. And yes, I agree it is a bit curt. But it is not against the rules.

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,758

    Re: ".Find" Returns Run-time error '91': if the Item Is Not Found.

    Quote Originally Posted by Tegglet View Post
    I will certainly try your suggestion though.
    You may want to consider the solution in post #2 as an alternative.

  8. #8
    Registered User
    Join Date
    12-21-2017
    Location
    Wokingham, England
    MS-Off Ver
    office 365 2013
    Posts
    46

    Re: ".Find" Returns Run-time error '91': if the Item Is Not Found.

    Hi Jazzer,
    Getting a bit confused here with all the activity!!! This is in response to all your posts.

    It seems to me that there might be an easier solution than hard-coding a date and searching for it, since it seems that this would need to be variable. But I don't quite get what your ultimate goal is.
    The hard coding was for the example only. In the real world the variable FirstMonday is loaded by other code.

    The ultimate goal is a project started in response to the suggestion you made a while ago about using VBA to construct the workbook from scratch. I was right when I said it was a bit beyond my VBA programming skills, not only am I way out of my comfort zone I have been shot into hyper space!! As Poirot would say it is exercising the little grey cells. ;-)

    The current task is to populate the worksheet for each month with receipts received each Monday taking into account Bank Holidays.

    I have two receipts every Monday and have successfully populated each monthly sheet with the correct entries assuming no Bank Holidays. The problem arises when dealing with the Bank Holidays.

    When a Monday falls on a holiday I get the receipt on the preceding Friday. I have a list of holidays on a separate sheet (to be hidden eventually) which is used by Workday_Intl(....) to get the date of the previous working day. Since Workday_Intl returns the previous workday regardless of whether the seed date is on the list of holidays I need to know if the seed date is on the holiday list before applying it.

    I had tried using BankHoliday as Range and using
    Please Login or Register  to view this content.
    Obviously I had something different as inserting your code seems to work whereas when I tried it before it wouldn't recognise both conditions or I would get the dreaded "Object Variable....Not set" message..

    I will continue using your code in the hope there is not something lurking in some dark dank corner waiting to leap out and bit me in the bum!

    BTW: I have now got a working sub to find every fourth Friday and populate the worksheets accordingly. It even deals with two Friday receipts in one month. Subs seem easier to get my head round than functions!

    Many thanks for your help.
    Tegglet

+ 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] error "the file could not been found" every time i open Excel
    By MaartenRo in forum Excel General
    Replies: 2
    Last Post: 02-09-2021, 01:35 AM
  2. [SOLVED] Listbox remove item yields error: "Unspecified" run-time error '-2147467259 (80004005)':
    By Wedge120 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-18-2016, 01:48 PM
  3. [SOLVED] Loop Creates "item not found error" on second pass
    By phbryan in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-16-2014, 02:24 PM
  4. [SOLVED] Range.find returns "Nothing" in error, not sure of cause
    By enphynity in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-14-2013, 04:00 PM
  5. [SOLVED] How to Count number of "Error" and "OK" after the word "Instrument" found in table row
    By eltonlaw in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-17-2012, 06:26 AM
  6. Me.Controls.Add returns "Compile error, method or data member not found"
    By mattisch in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-28-2007, 07:53 AM
  7. Run time error 1004: "No list was found.."
    By hachiroku in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-22-2006, 07:55 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