Macro to duplicate rows with content

Pontos

Board Regular
Joined
Mar 26, 2003
Messages
132
I have a table like this:
RepetitonsNamee-mailDepartmentTask number
3BobBob@yahoo.comODB.1.1
3MikeMike@yahoo.comROB.1.1
1EsterEster@yahoo.comSOB.1.1
2TedyTedy@yahoo.comSSB.1.1
5JohnJohn@yahoo.comROB.1.1
8JoeJoe@yahoo.comSOB.1.2
10MichaelMichael@yahoo.comODB.1.2
4SteveSteve@yahoo.comSSB.1.2
10BillyBilly@yahoo.comSSB.1.2

I need so many new rows as is the number in the A column.
And every value needs to be the same as the copied one.
Like this:
RepetitonsNamee-mailDepartmentTask number
3BobBob@yahoo.comODB.1.1
3BobBob@yahoo.comODB.1.1
3BobBob@yahoo.comODB.1.1
3MikeMike@yahoo.comROB.1.1
3MikeMike@yahoo.comROB.1.1
3MikeMike@yahoo.comROB.1.1
1EsterEster@yahoo.comSOB.1.1
2TedyTedy@yahoo.comSSB.1.1
2TedyTedy@yahoo.comSSB.1.1
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Are we looking at column A with Repetitons ?
This script assumes that:
Try this:
VBA Code:
Sub New_Insert_Rows()
'Modified  6/24/2022  1:24:21 AM  EDT
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Dim ans As Long
   
    For i = Lastrow To 2 Step -1
        ans = Cells(i, 1).Value
        Rows(i).Offset(1).Resize(ans - 1).Insert shift:=xlDown
        Rows(i).Resize(ans).FillDown
    Next
MsgBox "Done"
Application.ScreenUpdating = True
End Sub
 
Upvote 0
VBA Code:
Sub RowsCountByValue()
Dim i&, fr&, lr&, cn&, r&
cn = 1: fr = 1
lr = Cells(Rows.Count, "A").End(3).Row
    For r = lr To fr Step -1
        If IsNumeric(Cells(r, cn)) Then i = CLng(Cells(r, cn))
        If i >= 2 Then
            Rows(r).Copy
            Rows(r + 1).Resize(i - 1).Insert
        End If
    Next r
Application.CutCopyMode = 0
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,730
Members
448,987
Latest member
marion_davis

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