Create multiple rows

G

Guest

Hi--
Is there a simple way of duplicating a row multiple times based on a value?

For example, I want to create labels in word based on the number of packages
a customer has purchased. Word needs a separate record for each label
produced.
If i have the customer info in a row with the number of labels needed in the
final cell, is there a way of writing a macro to duplicate (either in the
same worksheet or a new one) that would create multiple rows based on the
value in the last cell?

Any advice would be appreciated!
 
O

okrob

Sub insert_Rows()
Dim rng As Range, i As Integer, cnt As Integer
Set rng = Cells(Rows.Count, 1).End(xlUp)

For i = rng.Row To 2 Step -1
' Change 2 to 1 if you don't have a header row

cnt = Cells(i, "F").Value
' this is the column with your label count change F to suit

If cnt <> 1 Then
Cells(i, 1).EntireRow.Offset(1, 0).Resize(cnt - 1).Insert
Cells(i, 1).EntireRow.Copy Destination:= _
Cells(i, 1).EntireRow.Offset(1, 0).Resize(cnt - 1)
Else
End If
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top