How to convert a long form table to wide form table in Excel?

前端 未结 2 484
北海茫月
北海茫月 2021-01-17 02:07

A picture is worth a thousand words. Let\'s say in one sheet I have the following table:

\"enter

相关标签:
2条回答
  • 2021-01-17 03:09

    Using VBA:

    Range("G1:K99").Clear
    For Each xx In Range("A:A")
        If xx.Value = "" Then Exit Sub
        Range("G1").Offset(xx.Value, 0) = xx.Value
        For e = 1 To 99
            If Range("G1").Offset(xx.Value, e) = "" Then
                Range("G1").Offset(xx.Value, e) = xx.Offset(0, 1).Value
                Exit For
            End If
        Next
    Next
    

    The table it's created from column "G". If you want another sheet:

    Sheets(2).Range("G1: ...
    

    add the Sheets before ...

    Without VBA, following the scheme:

    enter image description here

    Adding the formulas:

    M2 -> =IFERROR(MATCH(L2;$A$1:$A$8;);"")
    N2 -> =IFERROR(MATCH(L2;INDIRECT("$A" & (M2+1) & ":$A$8");)+M2;"")
    O2 -> =IFERROR(MATCH(L2;INDIRECT("$A" & (N2+1) & ":$A$8");)+N2;"")
    P2 -> =IFERROR(INDEX($B$1:$B$8;M2);"")          Autocomplete also columns to R
    

    and Autocomplete ...

    0 讨论(0)
  • 2021-01-17 03:09

    I can see another approach as well. Add two columns Count and Key.

    Add the formulas and expand:

    C2 -> =COUNTIF($B$2:B2;B2)
    D2 -> =B2&"|"&C2
    G2 -> =IFERROR(INDEX($A:$A;MATCH($F2&"|"&COLUMN(A1);$D:$D;0));"")
    
    0 讨论(0)
提交回复
热议问题