Copy data into inserted rows

philcart

Board Regular
Joined
Feb 12, 2003
Messages
177
Hi,
I have an Excel 2007 workbook which lists customer data in cols A to J. Each customer has a main ref (col B) and may have any number of secondary refs in cols L onwards. Col K shows how many secondary refs the customer has, and is used in the code below to determine how many blank rows to add for those customers that have 1 or more secondary refs (1 row per secondary ref)

Sub Insert_Row()
Dim LASTROW As Long
Dim I As Long
LASTROW = Range("C" & Rows.Count).End(xlUp).Row
For I = LASTROW To 2 Step -1
If ((IsNumeric(Cells(I, "K"))) And (Cells(I, "K") <> Empty)) Then
Range(Cells(I + 1, 1), Cells(I + Cells(I, "K"), 1)).EntireRow.Insert
End If
Next I
End Sub

What I need now is for the code to do 2 more things –
1. Once the blank rows have been inserted for e.g. the customer in row 5 who has 2 secondary refs (in L5 and M5), the value in L5 to be copied to B6, and the value in M5 to be copied to B7. (Could select, then transpose?)
2. Then copy the values in cells C5:J5 into the same columns in rows 6 & 7. (Not bothering with col A)

Basically, I’m consolidating main and secondary refs for each customer into one list.
Hope someone can help?
Cheers,
Phil
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,224,550
Messages
6,179,459
Members
452,915
Latest member
hannnahheileen

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