+ Reply to Thread
Results 1 to 10 of 10

Copy one value and paste it x number of times

  1. #1
    Registered User
    Join Date
    02-21-2011
    Location
    Nottingham, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Copy one value and paste it x number of times

    Hello all,

    I have a workbook with two sheets, one containing customer list and another containing the products.
    The number of customers and the number of products change daily.

    1) I need code that would copy each customer name and paste it in a third sheet, for the same number of times as there are products - in the same column.
    2) Then I need to copy and paste the products onto the third sheet, in the column next to the multiple customer name.

    I have attached an example.

    Can anyone PLEASE help me out as I'm going insane with trying to find a solution in the forum that would work for my scenario.

    Any help much appreciated!!
    Attached Files Attached Files

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,485

    Re: Copy one value and paste it x number of times

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    02-10-2011
    Location
    Copenhagen, DK
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Copy one value and paste it x number of times

    Hi,

    Use this loop to copy/paste. When you want to copy paste column 2, just change 1 to 2 in the code.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    02-10-2011
    Location
    Copenhagen, DK
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Copy one value and paste it x number of times

    Quote Originally Posted by KRAND View Post
    Hi,

    Use this loop to copy/paste. When you want to copy paste column 2, just change 1 to 2 in the code.

    Please Login or Register  to view this content.
    UPS, I forgot the Loop...

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-21-2011
    Location
    Nottingham, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Copy one value and paste it x number of times

    Thats just Brilliant!! Thanks for that.
    If there was a blank cell and some non product info at the bottom of the "Product" list (say 3 rows of non-product info), and I do not want this included in the combined list in "Results", would I change the last section of the code to something like:

    For Each rngItem In rngCustomer.Cells
    rngItem.Copy rngOutput.Resize(rngProduct.Rows.Count, 1)
    rngProduct.Copy rngOutput.Offset(0, 1).Resize(rngProduct.Rows.Count-3, 1)
    Set rngOutput = rngOutput.Offset(rngProduct.Rows.Count)
    Next

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,485

    Re: Copy one value and paste it x number of times

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here


    Rather than mess with the loop code just sort out the correct range to use by the variable rngProduct

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    02-21-2011
    Location
    Nottingham, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Copy one value and paste it x number of times

    Thanks for the advice and apologies for not tagging the code.. will remember for next time!

    Much appreciated, you've saved me contless hours' work and it works beautifully!

  8. #8
    Registered User
    Join Date
    06-29-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Copy one value and paste it x number of times

    can you post the spreadsheet with the code in it? I cant quite figure it out...

  9. #9
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Copy one value and paste it x number of times

    @ davidben13

    It looks like you're going to be out of luck on this one. jcb hasn't posted for a year and a half.

  10. #10
    Registered User
    Join Date
    08-02-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Copy one value and paste it x number of times

    Andy, thank you very much for this--I have never used Visual Basic, and I registered here just to see your code example. It was a huge boon for 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