我有一个基于行数据对excel行进行分组的问题。以下是示例数据。
我想基于Resource,Metro和Geo对数据进行分组。
我已经开始在下面编写一个宏,但需要一些帮助来完成这项工作。
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