|
本帖最后由 kwinawyeth 于 2012-10-2 15:28 编辑
是不是这样?- Private Sub Worksheet_Activate()
- Dim i As Long, j As Long, k1 As Long, k2 As Long
- Application.ScreenUpdating = False
- Rows("7:" & Cells(65536, 3).End(xlUp).Row).EntireRow.Hidden = False '取消所有隐藏的行
- For i = 2 To 7 '循环每个年级
- '找出每个年级的第一行
- For j = 7 To Cells(65536, 3).End(xlUp).Row
- If Cells(j, 1) <> "" Then
- If Left(Cells(j, 1), 1) = Sheets("数据设置").Cells(i, 7) Then
- k1 = j
- Exit For
- End If
- End If
- Next j
- If k1 < 1 Then Exit Sub
-
- '找出每个年级的最后一行
- k2 = k1 + 1
- Do While Cells(k2, 1) = ""
- k2 = k2 + 1
- If k2 > Cells(65536, 3).End(xlUp).Row Then Exit Do
- Loop
- k2 = k2 - 1
-
- '隐藏多余的班
- For j = k1 To k2
- If Cells(j, 3) > Sheets("数据设置").Cells(i, 8) And Cells(j, 3) <> "年级" Then
- Rows(j).EntireRow.Hidden = True '隐藏行
- End If
- Next j
- Next i
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|