如何使用excel宏在多个级别上对excel行进行分组

时间:2016-10-24 21:32:15

标签: excel vba excel-vba

我有一个基于行数据对excel行进行分组的问题。以下是示例数据。 Sample data for grouping the rows

我想基于Resource,Metro和Geo对数据进行分组。 Data after grouping

我已经开始在下面编写一个宏,但需要一些帮助来完成这项工作。

Public Sub GroupCells()
    Dim myRange As Range
    Dim GeoRange As Range
    Dim MetroRange As Range
    Dim ResourceRange As Range
    Dim GeosRange As Range
    Dim MetrosRange As Range
    Dim unionRange As Range


    Set myRange = Range("Resource")
    Set GeoRange = Range("Geo")
    Set MetroRange = Range("Metro")
    rowCount = Cells(Rows.Count, myRange.Column).End(xlUp).Row

    Set TypesRange = myRange.SpecialCells(xlTextValues)
    Set GeosRange = GeoRange.SpecialCells(xlTextValues)
    Set MetrosRange = MetroRange.SpecialCells(xlTextValues)
    Set unionRange = Union(TypesRange, GeosRange, MetrosRange)
    For Each grp In unionRange
    grp.Rows.Group
    Next

    End Sub

0 个答案:

没有答案