ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copy some information from sheet1 to sheet2 (https://www.excelbanter.com/excel-programming/326224-copy-some-information-sheet1-sheet2.html)

john_liu

Copy some information from sheet1 to sheet2
 
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



Bob Phillips[_6_]

Copy some information from sheet1 to sheet2
 
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)


"john_liu" wrote in message
...
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






All times are GMT +1. The time now is 04:06 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com