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
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