+ Reply to Thread
Results 1 to 7 of 7

Copy specific range to offset location

  1. #1
    Registered User
    Join Date
    01-13-2009
    Location
    Prince Rupert, BC
    MS-Off Ver
    Excel 97, 2003
    Posts
    54

    Copy specific range to offset location

    I would appreciate some ones help to correct a macro I'm trying to write. The macro copies 3 columns from Sheet1 to Sheet2 in a selected location. The 3rd column copied needs to be pasted in a different column in Sheet2.

    Please Login or Register  to view this content.
    Above copies Columns A, B & H (ranges) from Sheet1 and pastes to A, B & C columns in Sheet2 or depending on what cell was selected in Sheet 2 (1st, 2nd & 3rd columns). The requirement is to to have H pasted to Sheet2 F (6th column).

    I have tried several Target.Offset statements but have had no success. I've attached my sample sheet with what I have so far.

    Thanks in advance
    Attached Files Attached Files
    Last edited by Mister P; 01-21-2009 at 07:31 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492
    Try this instead:

    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    01-13-2009
    Location
    Prince Rupert, BC
    MS-Off Ver
    Excel 97, 2003
    Posts
    54
    JB

    Tried your code and yes it pastes in the correct columns but what I need is that the resulting paste start to a selected cell on Sheet2. If I select E17 on Sheet2 and run the macro the resulting paste should be column E, F & J starting at row 17.

    I will be using this macro to copy specified columns from a variety of sheets to assemble one combined sheet.

    Thanks

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492
    That second example doesn't match the request from the first. The first was A,B,F (nine cells) copied to A,G,H (offset by 1).

    Now your E17 example is a 1 to 1 paste? What's different? Are the ranges always nine cells? Will an xlDown work to select a range of cells, meaning thing there's a break in the data? Or does it have to be manually set?

  5. #5
    Registered User
    Join Date
    01-13-2009
    Location
    Prince Rupert, BC
    MS-Off Ver
    Excel 97, 2003
    Posts
    54
    JB

    I'm not explaining this well enough. Both requests are for the same columns in Sheet1 to be copied and pasted to Sheet2. My original code I included, would allow me (or any user) to select a specific column & cell in Sheet2 before running the macro. The resulting paste would start at the column & cell which was selected. I want to maintain this feature. The portion I'm having problems with is having the macrco offset the copied H to a position 5 columns to the right of where the A column pasted. In my second post the paste if started at E17 the first column pasted would be E, F J or 1st, 2nd and 6th columns. If the code you posted could be modified to allow the user where the paste should start on Sheet2 the problem would be solved.

    Hope this clarifies the request.

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531
    How about:

    Please Login or Register  to view this content.
    Assumes you're running this with Sheet2 being the active sheet... can be altered if not.

  7. #7
    Registered User
    Join Date
    01-13-2009
    Location
    Prince Rupert, BC
    MS-Off Ver
    Excel 97, 2003
    Posts
    54

    Works great

    Thank you DonkeyOte

    Tried your code and it works perfectly. This is exactly how I wanted the macro to be applied. I have considerable experience in programming but am really new to VBA and need assistance from time to time. Really appreciate your help.

    Cheers

+ 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