1

我有一张看起来像这样的表:

Group   | Name     | Comment   | Tag 1       | Tag 2       | Tag 3
-------------------------------------------------------------------
gr1       Joe        We are...   SYSTEM        SUGGESTION    PAINPOINT
gr1       Joe        I want...   PROCESS       ATTITUDE

我需要运行一个基本上生成这个的宏(我使用的是 Excel 2007)

Group   | Name     | Comment   | Tag 1       | Tag 2       | Tag 3
-------------------------------------------------------------------
gr1       Joe        We are...   SYSTEM
gr1       Joe        We are...   SUGGESTION
gr1       Joe        We are...   PAINPOINT
gr1       Joe        I want...   PROCESS
gr1       Joe        I want...   ATTITUDE

所以所有标签都得到重复的数据,但它们自己的行。这使我现在可以在一列中对信息进行排序和旋转。我目前不太擅长 VBA,希望能在这个特定问题上得到一些帮助。

我希望这已经足够清楚了。

4

1 回答 1

2

如果您真的需要将它作为 vba 代码,这里是一种可能的解决方案:(子例程中的一些附加注释) 经过尝试和测试

Sub Solution()

    'Select cell with 'Group' title
    'Result passed to 10th column to the right
    'Macro doesn't care of headers of result table

    Dim KOM As Range
    Dim partGNC As Variant
    Dim partTAG As Variant
    Dim resRow As Long
        resRow = ActiveCell.Row + 1
    For Each KOM In Range(ActiveCell.Offset(1, 0), ActiveCell.End(xlDown))

        partGNC = KOM.Resize(1, 3)
        partTAG = Range(KOM.Offset(0, 3), KOM.End(xlToRight))

        If KOM.Offset(0, 3).Address = KOM.End(xlToRight).Address Then

            Cells(resRow, KOM.Column + 10).Resize(1, 3) = partGNC
            Cells(resRow, KOM.Column + 13) = partTAG
            resRow = resRow + 1

        Else
            Cells(resRow, KOM.Column + 10).Resize(UBound(partTAG, 2), 3) = partGNC
            Cells(resRow, KOM.Column + 13).Resize(UBound(partTAG, 2), 1) = Application.Transpose(partTAG)
            resRow = resRow + UBound(partTAG, 2)
        End If


    Next

End Sub
于 2013-05-23T19:58:05.800 回答