Extract categories from columns into duplicated rows with new category

前端 未结 1 1456
后悔当初
后悔当初 2021-01-24 15:19

I have a table that looks like so:

Group   | Name     | Comment   | Tag 1       | Tag 2       | Tag 3
-----------------------------------------------------------         


        
相关标签:
1条回答
  • 2021-01-24 16:17

    If you really need to have it as vba code here is one of possible solution: (some additional comments inside subroutine) Tried and tested

    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
    
    0 讨论(0)
提交回复
热议问题