copy paste row multiple times

glaungani

New Member
Joined
May 5, 2018
Messages
8
Hi, i am using the below code to copy the data from each row and paste it below on same sheet by the times mentioned in column P (multiplier can be different for each row) .


Dim i As Long

For i = Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1
Rows(i).Copy
Rows(i).Resize(Range("P" & i)).Insert
Next i

Now i am not the best in coding so require some help to customize it.

The above code works fantastics but the only problem is when the multiplier is 0, then the code breaks. I would like to skip the row where the muliplier is 0 and move to the next one. can someone help me edit the above please.

thanks in advance.

cheers
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
How about
VBA Code:
For i = Range("A" & rows.Count).End(xlUp).Row To 2 Step -1
   If Cells(i, "P").Value > 0 Then
      rows(i).Copy
      rows(i).Resize(Range("P" & i)).Insert
   End If
Next i
 
Upvote 0
How about
VBA Code:
For i = Range("A" & rows.Count).End(xlUp).Row To 2 Step -1
   If Cells(i, "P").Value > 0 Then
      rows(i).Copy
      rows(i).Resize(Range("P" & i)).Insert
   End If
Next i
unbelievably simple solution to my prob. thanks for your prompt help, buddy.
 
Upvote 0
What is the error message & what was the value in col P?
 
Upvote 0
Glad you sorted it & thanks for letting us know.
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,028
Members
448,940
Latest member
mdusw

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