|
楼主 |
发表于 2018-9-9 11:55
|
显示全部楼层
- Sub 组级()
- Dim R1, C1, H1, H2, K1, k2 As Integer
- On Error Resume Next
- Err.Clear
- Set Sht1 = ActiveWorkbook.ActiveSheet
- If Err.Number <> 0 Then
- MsgBox "没有正打开的EXCEL文档"
- Exit Sub
- End If
- Err.Clear
- On Error GoTo 0
- R1 = ActiveCell.Row
- C1 = ActiveCell.Column
- H1 = Sht1.Range(Chr(64 + C1) & "65536").End(xlUp).Row
- On Error Resume Next
- Err.Clear
- K1 = CInt(Sht1.Cells(R1, C1))
- If Err.Number <> 0 Then
- MsgBox "请选中层级"
- Exit Sub
- End If
- Err.Clear
- On Error GoTo 0
- For i = R1 + 1 To H1
- k2 = CInt(Sht1.Cells(i, C1))
- If k2 = 0 Then
- Exit For
- ElseIf k2 <= K1 Then
- Exit For
- Else
- On Error Resume Next
- For K = 1 To k2 - K1
- Rows(i).Group
- Next
- Err.Clear
- On Error GoTo 0
- End If
- Next
- Sht1.Outline.SummaryRow = xlAbove
- End Sub
- Sub 取消组级()
- For i = 1 To 8
- On Error Resume Next
- Cells.Rows.Ungroup
- On Error GoTo 0
- Next
- End Sub
复制代码
|
|