我正在Windows 10上使用Excel 2013
如果我将工作表从$ G $ 4分成4个面板,分成4个面板。
我尝试过
sub Worksheet_Activate()
With ActiveWindow
.FreezePanes = False ' Remove previous settings
.SplitColumn = 7 ' $G
.SplitRow = 4 ' $4
.FreezePanes = True ' Use the settings
End With
Me.ScrollArea = "$G$4:$X$200"
end sub
但这只是第一步
我要特别a)禁用左上和右上面板中前3行的垂直滚动b)在左上方和左下方面板中禁用水平滚动c)无法向上滚动以显示左下和右下面板中的前三行d)使用右下滚动条不能水平滚动到前6列(A到F)
我如何使用VBA做到这一点?
我发现如何通过结合使用.split = true和.freeze = true来做到这一点>
没有.freeze = true,我有3个滚动条,用户仍然可以滚动(只有最大的滑块)。但是,如果我使用.freeze = true,则只剩下1个滑块:右下角的那个。
Private Sub Worksheet_Activate()
Dim rng as Range: set rng = Range('$B$4:$BF$63') ' Note: there are 2 rows used above and 1 row below
Me.ScrollArea = "" ' Clear the ScrollArea of the worksheet
With ActiveWindow ' See https://docs.microsoft.com/en-us/office/vba/api/excel.window.split
colSplit = 6 ' Actually: some code that will idenfify where I want to split --> colSplit
.FreezePanes = False ' Necessary: removes the current Panes (if any)
.Split = False ' Necessary: removes the current Split (if any)
.ScrollRow = rng.Row - 2 ' Show the 2 rows used above in the upper panes
.ScrollColumn = rng.Column ' Show the left column of the range
.SplitColumn = colSplit ' The last column in the left panes '
.SplitRow = rng.Row - 2 ' The first row I want to see in the upper panes
.FreezePanes = True ' Remove the scrollbars for the upper panes and the lower left pane
End With
'rng.Cells(1,colSpilt+1) makes sure that no column of the lower left pane can be scrolled into
Set rng = Range(rng.Cells(1, colSplit + 1).Address & ":" & rng.Cells(rng.Rows.count + 1, rng.Columns.count).Address)
Me.ScrollArea = rng.Address(True, True, xlA1) ' Set the ScrollArea of the worksheet --> only at the lower right pane
End Sub