我有一张看起来像这样的表:
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方面并不擅长,并且非常喜欢这个特殊问题。
我希望这很清楚。
答案 0 :(得分: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