Create duplicate rows

k.03a

New Member
Joined
Jul 12, 2011
Messages
19
Hi all,

This should be an easy one for those who know VBA.

I want to duplicate all my rows (20000 of them)

Basically I want to go from
col A
John
Daniel
David
Alex
....

to
col A
John
John
Daniel
Daniel
David
David
Alex
Alex
....

How can I do this?
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Try

Code:
Sub test()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = LR To 2 Step -1
    Rows(i).Copy
    Rows(i).Insert
Next i
End Sub
 
Upvote 0
Result appears in column B.
Code:
[COLOR="Blue"]Sub[/COLOR] GenerateDuplicates()

    [COLOR="Blue"]Dim[/COLOR] i [COLOR="Blue"]As[/COLOR] [COLOR="Blue"]Long[/COLOR], j [COLOR="Blue"]As[/COLOR] [COLOR="Blue"]Long[/COLOR]
    [COLOR="Blue"]Dim[/COLOR] arr1 [COLOR="Blue"]As[/COLOR] [COLOR="Blue"]Variant[/COLOR], arr2 [COLOR="Blue"]As[/COLOR] [COLOR="Blue"]Variant[/COLOR]
    
    arr1 = Range("A1:A" & Cells(Rows.count, "A").End(xlUp).Row)
    [COLOR="Blue"]ReDim[/COLOR] arr2(1 [COLOR="Blue"]To[/COLOR] UBound(arr1) * 2, 1 [COLOR="Blue"]To[/COLOR] 1)
    
    j = 1
    [COLOR="Blue"]For[/COLOR] i = 1 [COLOR="Blue"]To[/COLOR] UBound(arr1, 1)
        arr2(j, 1) = arr1(i, 1)
        arr2(j + 1, 1) = arr1(i, 1)
        j = j + 2
    [COLOR="Blue"]Next[/COLOR]
    
    Range("B1").Resize(UBound(arr2, 1)) = arr2

[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Sub[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,224,594
Messages
6,179,794
Members
452,943
Latest member
Newbie4296

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top