Results 1 to 3 of 3

Copy entire row x times and repeat

Threaded View

  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.

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