Copy some information from sheet1 to sheet2

  • Thread starter Thread starter john_liu
  • Start date Start date
J

john_liu

I have the following information on the sheet1

Products Color Quantity

Bike Blue 3
Chair Yellow 2
Table Brown 4
.....


What I want is to copy above information to the sheet2 according to the
number of quantity. In above example, the sheet2 should contain the infor
as;

Products Color Quantity

Bike Blue 3
Bike Blue 3
Bike Blue 3
Chair Yellow 2
Chair Yellow 2
Table Brown 4
Table Brown 4
Table Brown 4
Table Brown 4
.....

Could someone help me out. Thanks

J
 
Sub CopyData()
Dim iLastRow As Long
Dim i As Long, j As Long, k As Long

With Worksheets("Sheet1")
iLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
.Range("A1:C1").Copy Destination:=Worksheets("Sheet2").Range("A1")
For i = 2 To iLastRow
For k = 1 To .Cells(i, 3).Value
j = j + 1
.Cells(i, "A").Resize(1, 3).Copy Destination:= _
Worksheets("Sheet2").Cells(j, "A")
Next k
Next i
End With
End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)
 

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

Similar Threads


Back
Top