Excel formula 如何基于Id列将行转换为列

Excel formula 如何基于Id列将行转换为列,excel-formula,excel-2010,Excel Formula,Excel 2010,我想根据A列将行转换为列。有人能帮我介绍公式或任何设置吗 我不认为用excel formula创建这样的东西是可能的。我尝试创建一个可能有助于使用VBA的代码 尝试: 我想我对你想做的有点困惑。您想转置哪些行,基于什么标准?基于A列。A列中有3个唯一的值(1,2,3)。 Option Explicit Sub test() Dim LR As Long, LC As Long, i As Long, No As Long With ThisWorkbook.Workshee

我想根据A列将行转换为列。有人能帮我介绍公式或任何设置吗


我不认为用excel formula创建这样的东西是可能的。我尝试创建一个可能有助于使用VBA的代码

尝试:


我想我对你想做的有点困惑。您想转置哪些行,基于什么标准?基于A列。A列中有3个唯一的值(1,2,3)。
Option Explicit

Sub test()

    Dim LR As Long, LC As Long, i As Long, No As Long

    With ThisWorkbook.Worksheets("Sheet1")

        LR = .Cells(.Rows.Count, "A").End(xlUp).Row

        .Cells(LR + 3, 1).Value = "Event_Id"
        .Cells(LR + 4, 1).Value = "1"
        .Cells(LR + 5, 1).Value = "2"
        .Cells(LR + 6, 1).Value = "3"

        For i = 2 To LR
            No = .Cells(i, 1).Value

            If No = "1" Then

                LC = .Cells(LR + 4, .Columns.Count).End(xlToLeft).Column

                If .Cells(LR + 3, LC + 1).Value = "" Then
                    .Cells(LR + 3, LC + 1).Value = "Unit_Id"
                End If
                    .Cells(LR + 4, LC + 1).Value = .Cells(i, 2).Value

                If .Cells(LR + 3, LC + 2).Value = "" Then
                    .Cells(LR + 3, LC + 2).Value = "Qty"
                End If
                    .Cells(LR + 4, LC + 2).Value = .Cells(i, 3).Value

            ElseIf No = "2" Then
                LC = .Cells(LR + 5, .Columns.Count).End(xlToLeft).Column

                If .Cells(LR + 3, LC + 1).Value = "" Then
                    .Cells(LR + 3, LC + 1).Value = "Unit_Id"
                End If
                    .Cells(LR + 5, LC + 1).Value = .Cells(i, 2).Value

                If .Cells(LR + 3, LC + 2).Value = "" Then
                    .Cells(LR + 3, LC + 2).Value = "Qty"
                End If
                    .Cells(LR + 5, LC + 2).Value = .Cells(i, 3).Value

            ElseIf No = "3" Then
                LC = .Cells(LR + 6, .Columns.Count).End(xlToLeft).Column

                If .Cells(LR + 3, LC + 1).Value = "" Then
                    .Cells(LR + 3, LC + 1).Value = "Unit_Id"
                End If
                    .Cells(LR + 6, LC + 1).Value = .Cells(i, 2).Value

                If .Cells(LR + 3, LC + 2).Value = "" Then
                    .Cells(LR + 3, LC + 2).Value = "Qty"
                End If
                    .Cells(LR + 6, LC + 2).Value = .Cells(i, 3).Value

            End If

        Next i

    End With

End Sub