Excel 冻结特定列

问题描述

我只想冻结 Excel 工作表中的 S 列。不是来自 A-S,只是当我滚动过去时的 S 列。有没有办法做到这一点。尝试在线搜索,但找不到任何解决方案。 冻结窗格选项将冻结从 A 到 S 的所有列。 请告诉我。

解决方法

您可以在工作表模块中使用此代码自动将 split 应用/删除到您的窗口:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    'Declarations.
    Dim RngSplit As Range
    
    'Setting.
    Set RngSplit = Me.Range("S:S")
    
    'Focusing ActiveWindow.
    With ActiveWindow
        'Checking if ActiveWindow is already split.
        If .Panes.Count = 1 Then
            'Checking if the first visible column on the left is to the left of RngSplit column.
            If .ScrollColumn > RngSplit.Column Then
                'Splitting the ActiveWindow.
                .SplitColumn = 1
                .Panes(1).ScrollColumn = RngSplit.Column
            End If
        Else
            'Checking if the first visible column on the left in the second pane is to the right of or the actual RngSplit column.
            If .Panes(2).ScrollColumn <= RngSplit.Column Then
                'Unsplitting the ActiveWindow.
                .Split = False
            End If
        End If
    End With
        
End Sub

只要您更改选择,它就会激活。