+ Reply to Thread
Results 1 to 3 of 3

Copy entire row x times and repeat

Hybrid View

PY_ Copy entire row x times and... 08-26-2010, 03:21 PM
JBeaucaire Re: Copy entire row x times... 08-26-2010, 08:21 PM
PY_ Re: Copy entire row x times... 08-27-2010, 10:27 AM
  1. #1
    Forum Contributor PY_'s Avatar
    Join Date
    09-23-2008
    Location
    Houston
    MS-Off Ver
    Office 2016
    Posts
    289

    Copy entire row x times and repeat

    I found a code that will take the following:

    Column A | Column B
    apples | 2
    oranges | 3

    and produce:

    Column A | Column B
    apples | 2
    apples | 2
    oranges | 3
    oranges | 3
    oranges | 3


    How can i modify the code to do that with columns A:Z instead of just two columns?

    I can move the multiplier to any column i want if that will help.

    Sub CopyData()
    Dim lRow As Long
    Dim RepeatFactor As Variant
    
        lRow = 1
        Do While (Cells(lRow, "A") <> "")
            
            RepeatFactor = Cells(lRow, "B")
            If ((RepeatFactor > 1) And IsNumeric(RepeatFactor)) Then
                    
               Range(Cells(lRow, "A"), Cells(lRow, "B")).Copy
               Range(Cells(lRow + 1, "A"), Cells(lRow + RepeatFactor - 1, "B")).Select
               Selection.Insert Shift:=xlDown
               
               lRow = lRow + RepeatFactor - 1
            End If
        
            lRow = lRow + 1
        Loop
    End Sub
    Last edited by PY_; 08-27-2010 at 10:27 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

    Re: Copy entire row x times and repeat

    Change the "B" in line 12 to "Z".
    _________________
    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
    Forum Contributor PY_'s Avatar
    Join Date
    09-23-2008
    Location
    Houston
    MS-Off Ver
    Office 2016
    Posts
    289

    Re: Copy entire row x times and repeat

    Thank you so much JB!

+ 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