好吧,最好的答案是:不要将 excel 推到不仅仅是一个表格计算程序。但话虽这么说......让我们看看我们能做些什么。
基本思想:字面上只显示一个块并隐藏所有其他行。把它放在一个新模块中:
Public Sub goto_block(n As Long)
Dim ws As Worksheet
Dim i As Long
If n < 1 Then Exit Sub
Application.ScreenUpdating = False
Set ws = Worksheets(1)
ws.Rows.Hidden = True
ws.Rows( _
CStr((n - 1) * 19 + 1) & ":" & CStr((n - 1) * 19 + 19) _
).EntireRow.Hidden = False
Application.ScreenUpdating = True
ws.Cells((n - 1) * 19 + 1, "A").Select
End Sub
可以通过多种方式进行上下浏览。这显示了如何通过右键单击列 M/L 中的第一个(最顶部可见)单元格来上/下。(将其复制到工作表的模块中):
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
Dim curBlock As Long
If Target.Cells.Count = 1 Then
If (Target.Row Mod 19) = 1 Then
curBlock = Int((Target.Row - 1) / 19) + 1
If Not Application.Intersect(Target, Me.Columns("M")) Is Nothing Then
goto_block curBlock + 1
Cancel = True
Exit Sub
ElseIf Not Application.Intersect(Target, Me.Columns("L")) Is Nothing Then
goto_block curBlock - 1
Cancel = True
Exit Sub
End If
End If
End If
End Sub