Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

Public Sub CopyData()

' This routing will copy rows based on the quantity to a new sheet.
Dim Range1 As Range
Dim Range2 As Range
Dim i As Integer
' Set this
f there are no
Set Range1
Set Range2

for the range where the Quantity column exists. This works only i
empty cells
= Range("I1", Range("I1").End(xlDown))
= Cells(1, "I")

For Each Range2 In Range1


' Check if this cell actually contains a number
If IsNumeric(Range2.Value) Then
' Check if the number is greater than 0
If Range2.Value > 0 Then
' Copy this row as many times as .value
For i = 1 To Range2.Value
' Copy the row into the next emtpy row in sheet2
Range(Range2.Address).EntireRow.Copy Destination:=Sheets("Sh
eet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
Next
End If
End If
Next
End Sub

You might also like