+ Reply to Thread
Results 1 to 8 of 8

Paste method, defining the range

  1. #1
    Registered User
    Join Date
    11-16-2011
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    4

    Paste method, defining the range

    Hi,

    I am using the Paste method to paste data from the Clipboard into a range. It works fine when the range is defined like this:

    Please Login or Register  to view this content.
    It results in an error however when I use the following code:

    Please Login or Register  to view this content.
    Any ideas why?

    Thanks

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Paste method, defining the range

    Hi Bettingman, welcome to the forum.

    The issue is that "Cells(1, i - 1)" and "Cells(100, i + 2)" don't reference which worksheet you're using. Even though it's inside the WOrksheets("Sheet2").Range() qualifier, you still need to specify the worksheet for those Cells() references.
    Please Login or Register  to view this content.
    Or, more readable:
    Please Login or Register  to view this content.
    By specifying the destination after the Copy command, you don't need to put it on a separate line. You also only need to specify the first (top left) cell in the range where you want the data pasted.

    Hope that helps!

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,447

    Re: Paste method, defining the range

    Hi bettingman and welcome to the forum.

    GREAT QUESTION. This has fooled me many times. I also like Paul's answer but need to study and learn this syntax better.

    Would you try something for me. Put a period in front of the cell and see if that works. Let me know
    Use
    Please Login or Register  to view this content.
    Using the With Construct I've learned you need to do stuff like
    Please Login or Register  to view this content.
    Let me know how to remember using periods or not.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Forum Moderator vlady's Avatar
    Join Date
    09-22-2011
    Location
    Philippines - OLSHCO -Guimba-Nueva Ecija
    MS-Off Ver
    2021
    Posts
    4,366

    Re: Paste method, defining the range

    @ MarvinP tried it in 2003

    Compile error in .cells

    Error message
    Compile error
    invalid or unqualified reference
    I think people forget the word "THANK YOU!!!!" Do you still know it???

    There is a little star ( ADD REPUTATION ) below those person who helped you. Click it to say your "PRIVATE APPRECIATION TO THEIR EFFORT ON THEIR CONTRIBUTIONS "

    Regards,
    Vladimir

  5. #5
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Paste method, defining the range

    Adding periods only works when you use With/End With around that code.
    Please Login or Register  to view this content.
    is also:
    Please Login or Register  to view this content.
    You can use a "." before any object belonging to Sheet2 within the With/EndWith construct to make your code shorter and more readable.

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,447

    Re: Paste method, defining the range

    Ok then,

    How about this - will it work?
    Please Login or Register  to view this content.

  7. #7
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Paste method, defining the range

    It should, Marvin (assuming you copied something in a previous line, of course).

  8. #8
    Registered User
    Join Date
    11-16-2011
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Paste method, defining the range

    Thanks guys, very helpful!

    Sorry but I had to go away and couldn't respond earlier.

+ 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