VBA code to scroll all the way to the top

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
 
H

Harald Staff

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
 
C

Chip Pearson

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top