As my dataset is quite large (thousands of rows and dozens of columns), I would like to automate the process of:
Example:
My dataset possesses ID numbers in Column A. Each ID# possesses multiple parents in its own row. ID# 1 in Cell A2 possesses 4x nonzero parent numbers 265, 266, 32 and 7, in B2, C2, D2 and E2 respectively. Cell F2 = zero, and should be ignored.
Desired output in another sheet:
Any help would be greatly appreciated. Thank you!
This will do what you want.
Change the sheet names to match the sheet names you have.
Sub Sortstuff()
Dim ows As Worksheet
Dim tws As Worksheet
Dim trw&
Dim cel as range
Set ows = Worksheets("Sheet1") 'original sheet
Set tws = Worksheets("Sheet2") 'target sheet
For Each cel In ows.Range(ows.Range("B2"), ows.Range("B2").End(xlDown).End(xltoRight))
If cel <> 0 Then
trw = tws.Range("A" & tws.Rows.count).End(xlUp).Offset(1).Row
tws.Cells(trw, 2) = ows.Cells(cel.Row, 1)
tws.Cells(trw, 1) = cel.value
End If
Next
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.