Results 1 to 3 of 3

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

Threaded View

sam0287 range(cells(),cells()) from 2... 02-19-2010, 01:44 PM
Richard Schollar Re: range(cells(),cells())... 02-19-2010, 01:48 PM
sam0287 Re: range(cells(),cells())... 02-22-2010, 05:46 AM
  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:

    range(cells(1,1),cells(x,y)).value = range(cells(2,3),cells(a,b).value
    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:

    Sub test()
    
    Dim count As Integer
    
    count = 15
    
    Workbooks("Output Library").Sheets("Standard Sheet (2)").Range(Cells(1, 1), Cells(count, 3)).Value = _
    Workbooks("Excel Front End v1.2").Sheets("Inputs to Vensim").Range(Cells(1, 1), Cells(count, 3)).Value
    
    
    End Sub
    The thing that confuses me is that if I change the range references to a1 style then it works fine:

    Sub test()
    
    Dim count As Integer
    
    count = 15
    
    Workbooks("Output Library").Sheets("Standard Sheet (2)").Range("A1").Value = _
    Workbooks("Excel Front End v1.2").Sheets("Inputs to Vensim").Range("A1").Value
    
    
    End Sub
    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.

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