VBA code to scroll all the way to the top

  • Thread starter Thread starter lothario
  • Start date Start date
L

lothario

Hi,

This spreadsheet contains 5 sheets.
Each sheet has more than 3000 rows of data.

Can you tell me the VBA code:
a. Which takes the vertical scroll all the way to the top.
b. Where shold the code be located such that each time the user
clicks on tab of the respective sheet then this code gets
executed. So the user can scroll up and down in any sheet
but whenever he goes to another sheet the vertical scroll
is always at the top.

Thanks.
Luther
 
Hi Luther

Paste this in the ThisWorkbook module:

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
ActiveWindow.ScrollRow = 1
Cells(1, 1).Select
End Sub
 
Luther,

Put the following in the ThisWorkbook code module.

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If TypeOf Sh Is Excel.Worksheet Then
Application.Goto Sh.Range("A1"), True
End If
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com (e-mail address removed)
 
Back
Top