+ Reply to Thread
Results 1 to 6 of 6

Macro to copy and paste alternating cells

  1. #1
    Registered User
    Join Date
    03-09-2011
    Location
    Dubbo, NSW
    MS-Off Ver
    Excel 2003
    Posts
    20

    Macro to copy and paste alternating cells

    Hi All,

    I have a need to create a Macro that copies alternating cells until end of data.

    In my scenario I will end up with 2 sheets, each containing x number of rows (with the first row being a header row).

    Row 1 in Sheet 1 has a relation to Row 1 in Sheet 2.
    Row 2 in Sheet 1 has a relation to Row 2 in Sheet 2.
    Row 3 in Sheet 1 has a relation to Row 3 in Sheet 2.
    Row 4 in Sheet 1 has a relation to Row 4 in Sheet 2.

    and so on...

    What I am trying to achieve here is a Macro that copies:

    Sheet 1 Cell AA2 -> Sheet3 Cell A2
    Sheet 2 Cell P2 -> Sheet3 Cell A3

    ...Sheet 1 Cell AA3 -> Sheet3 Cell A4
    ...Sheet 2 Cell P3 -> Sheet3 Cell A5
    ...Sheet 1 Cell AA4 -> Sheet3 Cell A6
    ...Sheet 2 Cell P4 -> Sheet3 Cell A7
    ...Sheet 1 Cell AA5 -> Sheet3 Cell A8
    ...Sheet 2 Cell P5 -> Sheet3 Cell A9

    etc;

    and then keeps copying and pasting in that order and stops when Sheet 2 Column P = "" (blank).

    I would be most grateful for any assistance that can be rendered.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Macro to copy and paste alternating cells

    It will be good if you attach a sample file.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Macro to copy and paste alternating cells

    This is a bit crude. There is no checking that sheet 3 column A is empty.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    03-09-2011
    Location
    Dubbo, NSW
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: Macro to copy and paste alternating cells

    Hi Arlette,

    I have attached an example sheet.

    Rather than populate with a ton of data, I've populated with some on sheet 1 and sheet 2.

    If we use Sheet one column C (as the real sheet 1 column AA) and sheet 2 column B (as the real sheet 2 column P), the same effect would be achieved by copying and pasting:

    Sheet1.C2 -> Sheet3.A1
    Sheet2.B2 -> Sheet3.A2
    Sheet1.C3 -> Sheet3.A3
    Sheet2.B3 -> Sheet3.A4
    Sheet1.C4 -> Sheet3.A5
    Sheet2.B4 -> Sheet3.A6

    And so on until Sheet2 Column B contains an empty value.

    In the example sheet, Column A would end up reading:

    Jump
    One
    Sit
    Seven
    Sleep
    Nine
    Run
    Three


    Many thanks for your assistance.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    03-09-2011
    Location
    Dubbo, NSW
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: Macro to copy and paste alternating cells

    Thanks StevenM.

    Also thanks Arlette for taking the time to look at my post.

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Macro to copy and paste alternating cells

    Use this code. Change the cell references as required.
    Please Login or Register  to view this content.

+ 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