+ Reply to Thread
Results 1 to 7 of 7

Code fails with runtime error 91 in some case.

  1. #1
    Registered User
    Join Date
    01-09-2013
    Location
    Helsingborg, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    47

    Code fails with runtime error 91 in some case.

    Hello.

    I have pusseld together a code that matches data between ranges on different workbooks and copy pastes information belonging to sertain ranges from wb2 to wb1.

    The code works just fine on sheet "Car" and "Bike" in MainWorkbook. but when run on a more complex sheet "Plane" i get runtime error 91 "objecvariable or with block variable has not been defined". still when i press debug and stop the code it highlights the copy functions for range nr 3. and when i stop code after error and close it, the macro has still done its job as intended.

    Code i use is

    Please Login or Register  to view this content.
    Could anyone please help me find whats wrong and need be fixing?
    All the help i can get is appriciated!

    Cross Posts at http://www.ozgrid.com/forum/showthread.php?t=181410
    & http://www.mrexcel.com/forum/excel-q...some-case.html

    Cheers
    Attached Files Attached Files
    Last edited by lavinius; 08-02-2013 at 05:17 AM.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Code fails with runtime error 91 in some case.

    first correct the check for the find not returning anything.

    Please Login or Register  to view this content.
    Plane on has 1 data point in column I so the range to process is I7:I1048576, which is a waste of time. Either find the end row by coming up from the bottom when using the End method. or check the 2nd row contains something.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    01-09-2013
    Location
    Helsingborg, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Code fails with runtime error 91 in some case.

    Hello Andy!

    Thanks for your reply and help. Much appriciated.
    Might be a stupid Q but as im not that experienced with wba. how do i go about defining the range by finding the end row in that column?

    This code will be used in other workbook wich has many more sheets, where the ranges varies in length, and some ranges are empty aswell.
    Changing xlDown to xlUp didnt do much good

    Thanks again!

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Code fails with runtime error 91 in some case.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    01-09-2013
    Location
    Helsingborg, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Code fails with runtime error 91 in some case.

    Cheers for that Andy! Reputation Added for the help.

    Now i encounterd some other strange issue though. When changed from "If Not aCell Is Nothing Then" statement to "If Not bCell Is Nothing Then" statement when code runs first time Range C and F are deleted after find and match.

    Cheers

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Code fails with runtime error 91 in some case.

    this seems to work fine

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-09-2013
    Location
    Helsingborg, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Code fails with runtime error 91 in some case.

    Allright. Thanks Once again Andy!
    You helped me alot! Much Appriciated.

    Seems i put the same row number in all of the ranges (3), instead of (3, 6, 9 and 5).
    Could not figure out what was wrong :P.

    Thanks again for the help!

    Cheers

+ 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] Getting a runtime error with this code
    By rinser in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-20-2013, 10:22 AM
  2. [SOLVED] Range error in code, runs alone but not inside my full program, giving runtime error 1004
    By charizzardd in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-23-2012, 03:34 PM
  3. Code fails with error 1004
    By cdjones in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-22-2010, 06:27 PM
  4. Runtime Error Code 1004
    By laks in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-19-2007, 07:08 PM
  5. runtime error 9 problem with this code
    By cuewoz in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-03-2006, 09:54 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