+ Reply to Thread
Results 1 to 7 of 7

Run Time Error 91 - Can't find the source of it

  1. #1
    Registered User
    Join Date
    11-20-2012
    Location
    Haarlem, Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    9

    Run Time Error 91 - Can't find the source of it

    The below macro is updating fuel prices for a given month which can be in the current year, the last or the next one.

    The user gets one form to select the month of the update, then another form to select Current Year / Last Year / Next Year.

    Current Year and Last Year macros are working fine.

    The purpose of the Next Year macro is to check on the Fuel Price list if the year already exists - If Not, add a new cell with "2015"
    If the year is already entered, the macro will then check if the month selected on the first form already exists - If Not add a new cell with the month selected.

    Here is the macro :
    Please Login or Register  to view this content.


    On the line : Set YearFound = .Find(what:=Year(Date) + 1, after:=Range("A1"), LookIn:=xlValues, lookat:=xlWhole, _
    searchorder:=xlByColumns, searchdirection:=xlNext, MatchCase:=False, matchbyte:=False, searchformat:=False).Activate
    I am getting a Run Time Error 91, and I cannot find why.

    Thanks !

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Run Time Error 91 - Can't find the source of it

    Remove the .Activate from the end.
    David
    (*) Reputation points appreciated.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,509

    Re: Run Time Error 91 - Can't find the source of it

    You can't use Set and Activate. Lose the .Activate


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Run Time Error 91 - Can't find the source of it

    A most common reason for errors with Find is that what you are looking for isn't being found.

    You actually seem to be set up to handle that with the following If statement, but you need to lose .Activate.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Run Time Error 91 - Can't find the source of it

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    11-20-2012
    Location
    Haarlem, Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Run Time Error 91 - Can't find the source of it

    Thank you all. It did the trick !

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,509

    Re: Run Time Error 91 - Can't find the source of it

    You're welcome




    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ 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. Pivot table source not working run time error 1004
    By vba317 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-23-2014, 04:03 PM
  2. Pivot table source not working run time error 1004
    By vba317 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 04-22-2014, 05:15 PM
  3. Replies: 1
    Last Post: 10-13-2012, 01:47 AM
  4. Run-time error '1004'... Cannot open PivotTable source file
    By csh8428 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-16-2012, 03:22 PM
  5. Question on Source of Run-Time Error
    By ern2ern in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-15-2007, 10:56 PM

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