I'm trying to duplicate rows in sheet 1 based on the value indicated in column H of sheet 1, onto sheet 2.
I found a code that seems to work, but it changes the data in the original worksheet, instead of copying the rows into a different worksheet, say "Sheet2".
Sub CopyData()
'Updateby Extendoffice 20160922
Dim xRow As Long
Dim VInSertNum As Variant
xRow = 1
Application.ScreenUpdating = False
Do While (Cells(xRow, "A") <> "")
VInSertNum = Cells(xRow, "H")
If ((VInSertNum > 1) And IsNumeric(VInSertNum)) Then
Range(Cells(xRow, "A"), Cells(xRow, "H")).Copy
Range(Cells(xRow + 1, "A"), Cells(xRow + VInSertNum - 1, "H")).Select
Selection.Insert Shift:=xlDown
xRow = xRow + VInSertNum - 1
End If
xRow = xRow + 1
Loop
Application.ScreenUpdating = False
End Sub
How do I change this code such that it runs the macro in the original extract worksheet "Sheet1" and copies the rows into "Sheet2", if the value in column H is more than 0?
Sample data in Sheet1 would be as below. The value in container is in column H, which determines the number of rows to be copied & duplicated into Sheet2.
Supplier Dest Code Quantity Container
A US01 10001 1000 2
A US02 10002 500 4
B UK01 10001 0 0
C US01 10004 1300 1
The desired result in Sheet2 is as below:
Supplier Dest Code Quantity Container
A US01 10001 1000 2
A US01 10001 1000 2
A US02 10002 500 4
A US02 10002 500 4
A US02 10002 500 4
A US02 10002 500 4
C US01 10004 1300 1
Thank you.
r
? and where did you define ansSet
it ? is it suppose to be aRange
? – Shai Rado