我有一个像这样的Excel:
Name DOC STATUS
John ID OK
John ADRESS Incomplete
John SURNAME Missing
Lara ID OK
Lara ADRESS Missing
Lara SURNAME Missing
Rony ID OK
Rony ADRESS OK
Rony SURNAME OK
这个想法是,由于每个DOC,名称重复3次。有没有办法自动分组行?比如,每3行分组一次?
答案 0 :(得分:1)
如果您将Group
3行,并且由于您的数据是连续的行,您将获得组合在一起的1个大范围的行。
如果你想以某种方式分组,只有第一个值是可见的,而另外两个是折叠的,那么你实际上只需要分组第2和第3行。
<强>代码强>
Option Explicit
Sub GroupEveryNRows()
Dim i As Long, LastRow As Long
' modify "Sheet1" to your sheet's name
With Sheets("Sheet1")
' find last row with data in Column A
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
' loop from 2nd row till last row with data (assuming the first row has headers)
For i = 2 To LastRow Step 3
Range("A" & i + 1 & ":A" & i + 2).Rows.Group
Next i
End With
End Sub