VBA to copy a row and paste it in the next blank row

shafiq2

New Member
Joined
Jun 19, 2014
Messages
42
Hi,

I am looking for a VBA script to copy row A2 to H2 if K2 has a value if K2 is blank then nothing.

For example

Column AColumn BColumn CColumn DColumn DColumn FColumn GColumn HColumn IColumn JColumn K
Product namecompany nameDate Item number Serial Number Product typeColorPeriod Unit required
AB 1001020601GreenOne week 4
BAX1021010600Blue 3 days
Result
Column AColumn BColumn CColumn DColumn DColumn FColumn GColumn H
Product namecompany nameDate Item number Serial Number Product typeColorPeriod
AB 1001020601GreenOne week
BAX1021010600Blue 3 days
AB 1001020601GreenOne week
AB 1001020601GreenOne week
AB 1001020601GreenOne week

<colgroup><col style="width: 71pt; mso-width-source: userset; mso-width-alt: 3437;" width="94"> <col style="width: 77pt; mso-width-source: userset; mso-width-alt: 3730;" width="102"> <col style="width: 50pt; mso-width-source: userset; mso-width-alt: 2450;" width="67"> <col style="width: 48pt;" width="64"> <col style="width: 75pt; mso-width-source: userset; mso-width-alt: 3657;" width="100"> <col style="width: 65pt; mso-width-source: userset; mso-width-alt: 3145;" width="86"> <col style="width: 50pt; mso-width-source: userset; mso-width-alt: 2450;" width="67"> <col style="width: 53pt; mso-width-source: userset; mso-width-alt: 2560;" width="70"> <col style="width: 50pt; mso-width-source: userset; mso-width-alt: 2450;" span="2" width="67"> <col style="width: 71pt; mso-width-source: userset; mso-width-alt: 3437;" width="94"> <tbody>
</tbody>
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

<tbody>
</tbody>

Hi, I have created the following VBA code which copy row A2:I2 and paste it multiple time in the next blank row based on the value in column J2, so how to amend this code to move to the next row A3:I3 and paste it multiple time based on the value in J3 and then move on until the last used row.

Dim rws As Long
Dim rws1 As Long




With Range("A2:I2")
rws = .Rows.Count
rws1 = Cells(Rows.Count, 1).End(xlUp).Row
If Range("j2") > 0 Then

.Resize(rws).Copy Destination:=.Offset(rws1).Resize(rws * Range("J2").Value)
End If

End With

Thanks for your help.
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,038
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