VBA & Macro Problems

Restore an Excel Split-Pane View After a VBA Macro Runs

John WilsonJohn Wilson Dec 2, 2026 868 views

Question details

Restore the worksheet selection, split-pane focus, and horizontal scroll position after a macro moves columns.

Restore an Excel Split-Pane View After a VBA Macro Runs
Product
Microsoft Excel
Device & OS
not provided
Scenario
A VBA macro moves worksheet columns while the user works in a split-pane view.
Observed behavior
The user needs the worksheet view and horizontal scrolling position restored after the macro runs.
Before you start

Open the workbook in Excel and check that the intended worksheet has a split view under View > Split. Save the workbook as an Excel Macro-Enabled Workbook (.xlsm) if you need to retain VBA code, and enable macros only for trusted files.

Solution 1Recommended

Restore the selection and scroll position with VBA

Use this approach when the split panes still exist after the macro runs and you want to return to a chosen view.

The following example selects A2, sets a scroll position, activates pane 2, and scrolls that pane 11 columns to the right. Adjust these values to match your worksheet and desired view.

1
Open the VBA editor

In Excel, select Developer > Visual Basic. In the VBA editor, select Insert > Module if you need a place for the procedure.

2
Add the reset procedure

Paste this code into the module: Sub ResetView() Range("A2").Select ActiveWindow.ScrollColumn = 7 ActiveWindow.Panes(2).Activate ActiveWindow.SmallScroll ToRight:=11 End Sub

3
Run the reset after moving columns

Activate the intended worksheet and run ResetView from Developer > Macros after the column-moving macro finishes. Alternatively, add a call to ResetView at the end of that macro.

4
Adjust the view

Change the selected cell, ScrollColumn value, pane number, or ToRight value in the VBA editor until the view matches your needs. SmallScroll is relative to the active pane's current position.

Restore the selection and scroll position with VBA
Check the split first: Panes(2) requires at least two panes. The example restores a chosen view; it does not recreate a split removed by the macro or automatically remember the previous scroll position.
Free Microsoft Office alternative

Work with Excel spreadsheets in WPS Office

WPS Office is a free, lightweight alternative for working with spreadsheets in a familiar interface. Its Excel format compatibility makes it easy to move everyday workbook tasks between Office suites, although it does not fix an Excel-specific VBA view issue.

Use WPS Spreadsheets to navigate and edit worksheet dataOpen and save common Microsoft Excel formats, including XLSXGet started with a familiar spreadsheet interfaceUse a free, lightweight office suite for everyday work
microsoft office alternative - wps office

Frequently Asked Questions

Why does Panes(2).Activate fail?

The active window may not have a second pane. Check View > Split on the intended worksheet and recreate the split before running the procedure.

Does the sample code remember my previous scroll position?

No. It applies the values written in the procedure. Change ScrollColumn and SmallScroll to suit the view you want, or modify your macro to record and restore positions.

How do I run the view reset automatically?

Add a call to ResetView at the end of the column-moving macro, after making sure the intended worksheet and window are active.

Will WPS Office fix the Excel VBA macro?

No. WPS Office is an alternative for spreadsheet work, not a fix for an Excel-specific macro. Check macro compatibility before relying on an existing VBA workbook in another application.