Microsoft KB Archive/134829

= VB Macro to Align Worksheets with Top Worksheet =

Article ID: 134829

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Excel 97 Standard Edition
 * Microsoft Excel 98 for Macintosh

-



This article was previously published under Q134829



This article also applies to:
 * Microsoft Excel for Windows 95 7.0|7.0
 * Microsoft Excel for Windows 5.0c|5.0c
 * Microsoft Excel for Windows NT 5.0|5.0
 * Microsoft Excel for the Macintosh 5.0|5.0
 * Microsoft Excel for the Macintosh 5.0a|5.0a



SUMMARY
When worksheets have been grouped and a cell selected, that cell is then the active cell on each of the grouped sheets. In order to view that cell, each sheet must be individually manipulated to bring the active cell into view. The following is a sample Microsoft Visual Basic for Applications macro (Sub procedure) to align all the worksheets this way.



MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

Sample Visual Basic Procedure
Sub AlignSheets

' Remember which sheet was on top. Set TopSheet = ActiveSheet

' Do not update the screen until the end of the routine. Application.ScreenUpdating = False

' Store the sheet's position. TopRow = ActiveWindow.VisibleRange.Row LeftColumn = ActiveWindow.VisibleRange.Column

' Loop through each worksheet in the total worksheets. For Each xPage In Worksheets

' Activate worksheet. xPage.Activate

' Scroll the active sheet to the stored position. ActiveWindow.ScrollRow = TopRow ActiveWindow.ScrollColumn = LeftColumn

' Get the next worksheet. Next xPage

' Restore the original sheet. TopSheet.Activate

End Sub

