我有一个包含标题行的工作表,我想使用VBA对行进行分组。 我已经尝试过这种语法
Sub GroupItTogether()
Dim rLastCell As Range
Set rLastCell = ActiveSheet.Cells.Find(What:="*", After:=.Cells(1, 1), _
LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False)
Range("A2" & rLastCell).Select
Selection.Rows.Group
ActiveSheet.Outline.ShowLevels RowLevels:=1
End Sub
但是,这将产生以下错误:
参考无效或不合格
突出显示代码行: After:=.Cells(1, 1)
我该怎么做才能用VBA对所有行进行分组(没有标题)?
编辑
对于每个注释,我将语法编辑为以下内容,从而消除了该错误,但这并未将所有行分组(不包括标题)。 如何将其更新为按使用范围分组?
Sub GroupItTogether()
Dim rLastCell As Range
Set rLastCell = ActiveSheet.Cells.Find(What:="*", After:=Cells(1, 1), _
LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False)
Range("A2" & rLastCell).Select
Selection.Rows.Group
ActiveSheet.Outline.ShowLevels RowLevels:=1
End Sub