+ Reply to Thread
Results 1 to 3 of 3

Pasting values between ranges in different workbooks: "Range" works but "Cells" doesn't

  1. #1
    Registered User
    Join Date
    01-11-2013
    Location
    Lima, Peru
    MS-Off Ver
    Excel 2010
    Posts
    2

    Pasting values between ranges in different workbooks: "Range" works but "Cells" doesn't

    Hello! I'm pasting ranges from one workbook to another without actually activating either.
    For the "range1" variable I'm using "Range()", and for the "range2" variable I'm using "Cells()".

    I'd like to use Cells() for both ranges (easier to loop through numbers than through characters, AFAIK), but I can't use Cells() for the range1. Why is this?

    Thanks!

    Option 1: Range() for range1 and Cells() for range2 -> works!
    Please Login or Register  to view this content.
    Option 2: Cells() for range1 and Cells() for range2 -> Run-time error '1004': Application-defined or object-defined error
    Please Login or Register  to view this content.
    Last edited by Flaubert; 01-13-2013 at 02:17 PM.

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

    Re: Pasting values between ranges in different workbooks: "Range" works but "Cells" doesn'

    You can use cells for range1 but you are missing something.

    In fact you are missing it from both lines of code - the range2 line probably only works because the active sheet when you run the code is 'para Claudia'.

    Anyway, what you are missing is worksheet/workbook references for Cells.

    Here's one way to fix it.
    Please Login or Register  to view this content.
    The dots in front of Cells tie them to the workbook/worksheet in the With statement.

    By the way, how are you looping?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    01-11-2013
    Location
    Lima, Peru
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Pasting values between ranges in different workbooks: "Range" works but "Cells" doesn'

    Ah, I see!! That makes a lot of sense, because whenever I tried pasting from within the same active worksheet, it DID work.

    Thanks a lot!

    And naturally in the code I showed I wasn't looping in any way, but I intend to add loops later, so I had to get this working first =)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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