您可以尝试一下(在工作表代码模块中)。每次选择更改时,它都会在第一列中向上检查“Summary*”等内容:如果工作表尚未冻结到该行,它将进行调整。
一个困难是,要向上滚动,您必须单击顶部窗格中的某一行...
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Static lastFreeze As Long
Dim c As Range, r As Long, sel As Range
Set sel = Selection
'get the first cell on the selected row, then
' go up until find a content like "Summary*"
Set c = Target.Parent.Cells(Target.Cells(1).Row, 1)
Do While (Not c.Value Like "Summary*") And c.Row > 1
Set c = c.Offset(-1, 0)
Loop
'need to switch freeze location?
If c.Row > 1 And c.Row <> lastFreeze Then
ActiveWindow.FreezePanes = False
'prevent re-triggering event
Application.EnableEvents = False
Application.GoTo c.Offset(-1, 0), True
c.Offset(1, 0).Select
ActiveWindow.FreezePanes = True
sel.Select
Application.EnableEvents = True
lastFreeze = c.Row
End If
End Sub