+ Reply to Thread
Results 1 to 7 of 7

Macro to copy a cell range and paste to a new sheet 'n' times where 'n' defined by formula

  1. #1
    Registered User
    Join Date
    05-09-2013
    Location
    Connecticut, U.S.A.
    MS-Off Ver
    Excel 2010
    Posts
    7

    Macro to copy a cell range and paste to a new sheet 'n' times where 'n' defined by formula

    Hello,

    I'm looking for a VBA macro that will take a variable range of data from columns B through D and copy it to a new sheet "N" times. "N" will be defined by a count from another column.

    Sample attached with "Before" and "After" tabs.
    Sample.xlsx

  2. #2
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Macro to copy a cell range and paste to a new sheet 'n' times where 'n' defined by for

    Hello,

    try this:
    Please Login or Register  to view this content.
    Please use [CODE]-TAGS
    When your problem is solved mark the thread SOLVED
    If an answer has helped you please click to give reputation
    Read the FORUM RULES

  3. #3
    Registered User
    Join Date
    05-09-2013
    Location
    Connecticut, U.S.A.
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Macro to copy a cell range and paste to a new sheet 'n' times where 'n' defined by for

    Hi tehneXus,

    Thanks for your reply. Your example is close to what I need, but I need the formula to check the entire column for columns B through D. The rows of data will vary, I just used 3 rows of data for my sample, but it might be 2 rows, it might be 30 rows depending on the product.

  4. #4
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Macro to copy a cell range and paste to a new sheet 'n' times where 'n' defined by for

    Hi,

    that's correct, with four it fails,.. try:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-09-2013
    Location
    Connecticut, U.S.A.
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Macro to copy a cell range and paste to a new sheet 'n' times where 'n' defined by for

    Hi TehneXus,

    That works great for the sample I provided, thank you much!
    Unfortunately now I'm trying to apply it to my main worksheet (which has been a work in progress) and due requests from above I've had to change the placement of where the columns of originating data are, as well as where the data is delivered. My originating data Columns are now C, D, and E with the number of times to be copied found in Column R. The data is now being delivered to Columns G, H, and I starting in Row 3.

    I'm still new to vba and everything I've done before has used specifically named cells, so I'm trying to determine how your example is pulling the data. I've tried to change the numbers in the range, but haven't come up with the correct spots. Can you tell me if my annotations to the following are correct?


    Please Login or Register  to view this content.
    I've tried changing my range and been able to get the code to deliver to row 3, but can't get it to go over to column G (7). I also have tried getting it to pull the value of # of times to copy from R2 (2, 18) - but I get an error there as well.

  6. #6
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Macro to copy a cell range and paste to a new sheet 'n' times where 'n' defined by for

    Hi,

    please check attached example: Sample.xlsm

    contains:
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    05-09-2013
    Location
    Connecticut, U.S.A.
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Macro to copy a cell range and paste to a new sheet 'n' times where 'n' defined by for

    Excellent! That did it! Thanks for the further explanation on this as well, I can see now where I was making my mistakes in trying to get it to point to a new column and it will help me in the future if I need to change this code.

+ 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