+ Reply to Thread
Results 1 to 10 of 10

Macro to copy data multiple times

  1. #1
    Registered User
    Join Date
    03-15-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    5

    Macro to copy data multiple times

    Hi All,

    First post and i hope you can help me. I am a complete novice when it comes to coding, i have done some basics but nothing like this.

    What i have is two sheets, one will provide multiple lines of data including a reference, the second sheet will provide multiple lines of data each with a reference and other information.

    I need a macro to take each line in the second sheet and duplicate it as many time as there is lines in the first sheet, copy accross the reference from the first in one cell and the referece for the second into the next cell.

    First sheet:
    Reference
    1
    2
    3
    4

    Second sheet
    Reference
    A
    B
    C
    D
    E

    Third Sheet
    Ref 2 Ref 1
    A 1
    A 2
    A 3
    A 4
    B 1
    B 2
    B 3
    B 4
    C 1
    C 2
    C 3
    C 4
    D 1
    D 2
    D 3
    D 4
    E 1
    E 2
    E 3
    E 4

    I hope that makes sense, there will obviously be other data but this is my issue, any help anyof you can offer i would be very grateful and forever in your debt.

    Thanks

  2. #2
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Macro to copy data multiple times

    There could be an easier way to do this, but this should work for you

    Please Login or Register  to view this content.
    If you liked my solution, please click on the Star -- to add to my reputation

    If your issue as been resolved, please clearly state so and mark the thread as [SOLVED] using the thread tools just above the first post.

  3. #3
    Registered User
    Join Date
    03-15-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Macro to copy data multiple times

    Thanks for your help, however it does not give what i need.

    I have attached two files, one is what your macro returned (Book 2) and one is what i would like it to return (Book 3)

    In Book 3 you will see three sheets, sheet one haveing a reference, sheet two having a reference and then in sheet 3 is what i would like the maco to do.

    Please help if you can.

    Thanks

    Book2.xlsmBook3.xlsx

  4. #4
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Macro to copy data multiple times

    i tihnk i just misjudged your desired output, try this

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    03-15-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Macro to copy data multiple times

    Thanks again for your reply, however it still does not work

    I enetered your code but the results, as attached are not the desired output.

    Anymore help would be gratly appreciated.
    ThanksBook1.xlsm

  6. #6
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Macro to copy data multiple times

    you last data set started on row 2 so i edited the macro to start at row 2, bellow is code to start at row 1

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    03-15-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Macro to copy data multiple times

    Thanks again for a swift reply, however it is still not the output i would like, your code dupliactes the rows, but puts the numbers against the numbers not letters with numbers and also overwrites the sheet 1 not placing it on sheet 3

    You code in in book 1 attached and the output i want is in sheet 3 of book 3

    ThanksBook1.xlsmBook3.xlsx

  8. #8
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Macro to copy data multiple times

    the code in post # 4 is giving me your exact output, please see attached
    Attached Files Attached Files

  9. #9
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Macro to copy data multiple times

    I figured out where our disconect was, the code needs to be entered into a new module, not into the sheet code. when it is working in the sheet code it is only refering to one sheet the whole time, where as the macro is designed to loop through 3 sheets.


    try putting the code in a new module and let me know if that works for you.

  10. #10
    Registered User
    Join Date
    03-15-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Macro to copy data multiple times

    works perfect! you are a star and thank you so much for bearing with me

+ 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