Restore an Excel Split-Pane View After a VBA Macro Runs
Question details
Restore the worksheet selection, split-pane focus, and horizontal scroll position after a macro moves columns.

- 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.
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.
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.
In Excel, select Developer > Visual Basic. In the VBA editor, select Insert > Module if you need a place for the 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
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.
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.

Recreate a split removed by the macro
Use this if the macro removed the split and the pane referenced by the reset code no longer exists.
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.

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.




