excel - excel中动态卡住 Pane

标签 excel

我有一个 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 吗?即,最初 titleSummary A 将被卡住。然后,当用户向下滚动直到下一部分时,TitleSummary 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/

相关文章:

c# - 在 Excel C# 中的特定单元格中插入文本

excel - 没有 VBA 的迭代/循环替代

excel - 我可以将 =Offset() 的范围结果存储在另一个单元格中吗?

Excel 错误或功能 : "IF" isn't case sensitive?

mysql - 用java编写的excel文件更改顺序

java - Java 中的 Excel 生成问题

.net - 使用 .net 将 Excel 转换为 pdf

excel - Excel 数据中的变音符号

php - 表不在同一个顺序 mySQL

excel - 如何在两张纸之间链接单元格,以便在第二张纸上更新值