included in this xlsx excel
this macro should copies rows based on a value in a column.
error:
Run-time error 424 object req.
then debug option
line sheet2.Cells(1, 1).CurrentRegion.ClearContents
this is the macro
Sub expandIt()
Dim pasteRow As Long, pasteRow2 As Long
'clear existing data
Sheet2.Cells(1, 1).CurrentRegion.ClearContents
'Copy header
Sheet1.Activate
Sheet1.Range(Cells(1, 1), Cells(1, 8)).Copy Destination:=Sheet2.Cells(1, 1)
'Copy each row to the required number of cells
For Each cl In Range(Sheet1.Cells(2, 8), Sheet1.Cells(2, 8).End(xlDown))
Sheet1.Range(Cells(cl.Row, 1), Cells(cl.Row, 7)).Copy
pasteRow = Sheet2.Cells(65536, 7).End(xlUp).Row + 1
If Sheet1.Cells(cl.Row, 8) = 1 Then
Sheet1.Range(Cells(cl.Row, 1), Cells(cl.Row, 7)).Copy Destination:=Sheet2.Cells(pasteRow, 1)
Else
pasteRow = Sheet2.Cells(65536, 7).End(xlUp).Row + 1
pasteRow2 = pasteRow + Sheet1.Cells(cl.Row, 8) - 1
Sheet1.Range(Cells(cl.Row, 1), Cells(cl.Row, 7)).Copy _
Destination:=Sheet2.Range("$A$" & pasteRow & ":$A$" & pasteRow2)
End If
Next
'Fill Qty with 1's
Sheet2.Range("$H$2:$H$" & pasteRow2) = 1
End Sub
Thanks
chris
Bookmarks