+ Reply to Thread
Results 1 to 3 of 3

range(cells(),cells()) from 2 different workbooks, run time error 1004

  1. #1
    Registered User
    Join Date
    12-19-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    7

    range(cells(),cells()) from 2 different workbooks, run time error 1004

    Hi guys,

    I've been trying to copy values from one range to another, and the ranges need to be dynamic. Normally I use a combination of the 'range' and 'cells' properties, like this:

    Please Login or Register  to view this content.
    or something similar, and it works fine.

    However, when I try to do this across two workbooks I get a runtime error. I've isolated the piece of code causing the problem as here:

    Please Login or Register  to view this content.
    The thing that confuses me is that if I change the range references to a1 style then it works fine:

    Please Login or Register  to view this content.
    Anyone have any ideas why the second sub works but the first doesn't?

    Thanks, Sam.

    p.s. I realise I could use copy and paste for this, was just wondering why this method didn't work in this instance.
    Last edited by sam0287; 02-22-2010 at 05:35 AM.

  2. #2
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264

    Re: range(cells(),cells()) from 2 different workbooks, run time error 1004

    Hi Sam

    In the first, you need to fully qualify the Cells objects (ie on which sheets/workbooks they appear) as otherwisse by default (in a standard module) they refer to the activesheet (so you have a range on one sheet, but then try to apply cells on another = mismatch):

    Please Login or Register  to view this content.
    Note the addition of the periods before th Cells on the left hand side of the statement, and the "Workbooks("Excel Front End v1.2").Sheets("Inputs to Vensim")." before the Cells on the right hand side - both are fully qualifying the Cells property.

    Richard
    Richard Schollar
    Microsoft MVP - Excel

  3. #3
    Registered User
    Join Date
    12-19-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: range(cells(),cells()) from 2 different workbooks, run time error 1004

    Brilliant, thanks a lot!

+ 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