我有一个 Excel 工作表,其中包含以下格式的数据:
Title
Summary A
A info 1
A info 2
A info 3
Summary B
B info 1
B info 2
Summary C
所以现在我只有“标题”作为 Excel 中的卡住 Pane 。它工作正常,但有大量数据,因此当您处于工作表中间时,很难知道您是在 summary A
还是 summary B
中工作。
有人知道如何动态卡住 Pane 吗?即,最初 title
和 Summary A
将被卡住。然后,当用户向下滚动直到下一部分时,Title
和 Summary B
将被卡住,依此类推。
最佳答案
您可以尝试一下(在工作表代码模块中)。每次选择更改时,它都会在第一列中向上检查“摘要*”等内容:如果工作表尚未卡住到该行,它将进行调整。
一个困难是要向上滚动,您必须单击顶部 Pane 中的某一行...
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
关于excel - excel中动态卡住 Pane ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11266012/