|
话不多说,直接上附件
另附代码如下
Private Sub Worksheet_SelectionChange(ByVal Target As Range) '鼠标选择单元格事件
Dim x As Integer, r As Integer, z As Integer
x = Target.Row
r = Sheets(1).Cells.Find("*", , , , , xlPrevious).Row
z = x + 1
If x > 1 And Cells(x, 3) = "" And Cells(x, 1) <> "" Then
If Cells(x, 1) = "节" Then
Do
z = z + 1
If Cells(z, 1) <> "" Then
Exit Do
End If
Loop Until z = r
If z = r Then
Range(Cells(x + 1, 1), Cells(z, 1)).Select
If Selection.RowHeight = 0 Then
Selection.Rows.AutoFit
Else
Selection.RowHeight = 0
End If
Else
Range(Cells(x + 1, 1), Cells(z - 1, 1)).Select
If Selection.RowHeight = 0 Then
Selection.Rows.AutoFit
Else
Selection.RowHeight = 0
End If
End If
ElseIf Cells(x, 1) = "章" Then
Do
z = z + 1
If Cells(z, 1) = "章" Then
Exit Do
End If
Loop Until z = r
If z = r Then
Range(Cells(x + 1, 1), Cells(z, 1)).Select
If Selection.RowHeight = 0 Then
Selection.Rows.AutoFit
Else
Selection.RowHeight = 0
End If
Else
Range(Cells(x + 1, 1), Cells(z - 1, 1)).Select
If Selection.RowHeight = 0 Then
Selection.Rows.AutoFit
Else
Selection.RowHeight = 0
End If
End If
ElseIf Cells(x, 1) = "册" Then
Do
z = z + 1
If Cells(z, 1) = "册" Then
Exit Do
End If
Loop Until z = r
If z = r Then
Range(Cells(x + 1, 1), Cells(z, 1)).Select
If Selection.RowHeight = 0 Then
Selection.Rows.AutoFit
Else
Selection.RowHeight = 0
End If
Else
Range(Cells(x + 1, 1), Cells(z - 1, 1)).Select
If Selection.RowHeight = 0 Then
Selection.Rows.AutoFit
Else
Selection.RowHeight = 0
End If
End If
Else
End If
End If
End Sub
- Private Sub Worksheet_SelectionChange(ByVal Target As Range) '鼠标选择单元格事件
-
- 'iEndRow 数据最后行
- 'iCurRow 当前所选行
- Dim iCurRow As Integer, iEndRow As Integer, i As Integer
-
- If Target.Count > 1 Then Exit Sub
-
- iEndRow = UsedRange.Rows.Count
- iCurRow = Target.Row
-
- If iCurRow = 1 Then Exit Sub
- If iCurRow >= iEndRow Then Exit Sub
-
- Select Case Cells(iCurRow, 1)
- Case "章"
- i = iCurRow + 1
- Do While Cells(i, 1) <> "章" And i <= iEndRow
- i = i + 1
- Loop
- Rows(iCurRow + 1 & ":" & i - 1).Hidden = Not Rows(iCurRow + 1).Hidden
- Case "节"
- i = iCurRow + 1
- Do While Len(Cells(i, 1)) = 0 And i <= iEndRow
- i = i + 1
- Loop
- Rows(iCurRow + 1 & ":" & i - 1).Hidden = Not Rows(iCurRow + 1).Hidden
- End Select
- End Sub
复制代码
|
|