开发者

Excel - How to reformat nested table?

I have exported excel table like that

Excel - How to reformat nested table?

but i need another format like that:

开发者_StackOverflow 00008BN07 item1 subitem1 2,000 6 872,320

00008LN02A item2 subitem1 2,000 10 099,340

.....

020876071 item5 subitem1 1,000 294,260

020876071 item5 subitem2 2,000 294,260

020876071 item5 subitem3 3,000 294,260

How I can reformat first table to second view? Mbe some simple vba script?

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜