Excel - How to reformat nested table?
I have exported excel table like that
Thanks!
If the columns are A, B, and C, for name, item, and subitem respectively, try this code. It makes not claims to try to be optimized. When it has run, sort on column C, and delete all the junk that does not contain "SubItem" in column C.
Sub FillTable()
Dim lRowCurr As Long
Dim lRowColA As Long
Dim lRowColB As Long
lRowCurr = Cells(Rows.Count, 3).End(xlUp).Row
Do
If InStr(1, Cells(lRowCurr, 3), "subitem") Then
lRowColA = Cells(lRowCurr, 1).End(xlUp).Row
lRowColB = Cells(lRowColA, 2).End(xlDown).Row
Cells(lRowCurr, 1) = Cells(lRowColA, 1)
Cells(lRowCurr, 2) = Cells(lRowColB, 2)
End If
lRowCurr = lRowCurr - 1
Loop While lRowCurr > 0
End Sub
精彩评论