EXCEL: Notes & Examples on programming FreezePanes & Splits
Esteemed Forum Participants and Lurkers:
===============================
EXCEL
Just posted this to make it easier to search for info on Panes in Excel. Programming Panes can be a real PAIN!
Code:
Option Explicit
'Test & Demo Macro for Panes and Splits
'Panes & Splits operations MUST be done on the Active Window
Sub Panes_Splits()
Dim i As Integer 'misc. Loop index
'
'Comment this On and Off to test the effects of Screen Updating
'Application.ScreenUpdating = False 'Turn Screen Update OFF
'Show the number of Freeze or Split Planes in the Active Window
MsgBox (ActiveWindow.Panes.Count & " Panes")
'Show the index of the Active Pane
'1: Top (if 2) or Top left (if 4)
'2: Bottom (if 2) or top right (if 4)
'3: Bottom left
'4: Bottom right
MsgBox ("Active Pane: " & ActiveWindow.ActivePane.Index)
'Show the visible area in the active window for all of the panes
For i = 1 To ActiveWindow.Panes.Count
MsgBox ("Pane " & i & " " & ActiveWindow.Panes(i).VisibleRange.Address)
Next i
'Turn off FreezePanes
ActiveWindow.FreezePanes = False
'Turn off Splits
ActiveWindow.Split = False
'OR:
ActiveWindow.SplitRow = 0
ActiveWindow.SplitColumn = 0
'How to turn on specific panes?
'Panes/Splits are created based on the position of the SELECTION in the
' VISIBLE area in the ACTIVE WINDOW.
'Visibility and Pane/Split IS affected by the Application.ScreenUpdating state!
'
'If the SELECTION is NOT at the top of the window, a horizontal Freeze/Split
' will be created above the SELECTION.
'If the SELECTION is NOT at the left edge of the window, a vertical Freeze/Split
' will be created at the left edge of the selection.
'If the SELECTION is at the Top Left corner of the visible window, the Freeze/Split
' will be created at the center of the window, splitting the window into
' approximately equal Quadrants.
'If the SELECTION is NOT VISIBLE in the window, the window will be reset so that
' cell A1 is in the top left corner of the visible window, and the the Freeze/Split
' will be created from that position.
'If Application.ScreenUpdating = False and the selection is not visible in the
' current view of the screen, the current screen view will be split into
' approximate quadrants.
'Run this macro with Cell D4 prepositioned in various positions on the screen
Range("D4").Select
ActiveWindow.Split = True
'Turn Screen Updating ON
Application.ScreenUpdating = True
'If you need to reposition the view so that a particular cell is in the top left corner:
'Application.Goto Range("$G$6"), True 'Force Scroll to indicated cell
End Sub