Scroll to top of page code

P

peter.thompson

I have a worksheet where the first 6 rows are 'frozen'

When a worksheet is activated, I would like the sheet to be 'scrolled
to the top. Tired Range.("A7").select, however the worksheet does no
scroll to the top.

Would appreciate anyone helping with the suggested code to make thi
happen.

Cheers

Peter (new to VBA
 
M

Mark Lincoln

Enter this code in the sheet in question:

Private Sub Worksheet_Activate()
Range("A7").Select
End Sub
 
P

peter.thompson

Hi Mark, I've tried that, the cursor moves to the cell, but the page
doesn't 'scroll up' for some reason...

Cheers

Peter
 
N

Norman Jones

Hi Peter,

Try:

'=============>>
Private Sub Worksheet_Activate()
Application.Goto Reference:=Range("A7"), Scroll:=True
End Sub
'<<=============

This is worksheet event code and should be pasted into the worksheets's code
module (not a standard module and not the workbook's ThisWorkbook module):

Right-click the worksheet's tab
Select 'View Code' from the menu and paste the code.
Alt-F11 to return to Excel.


---
Regards,
Norman


"peter.thompson"
 
M

Mark Lincoln

Peter, I'm puzzled -- I get the same behavior both with my code and
with Norman's, and I've never had mine fail in use in any worksheet in
which I've used it.

I'm curious as to why my code didn't work for you. Did you run it in
the worksheet's code module?
 
P

peter.thompson

Hi Mark,

Am doing a few other things at the same time, see code below. Probabl
why it isn't working in this scenario. Unfortunately I'm too much of
newbie to figure out why!

Sincerely appreciate your asistance.

Public Sub Worksheet_Activate()
Application.ScreenUpdating = False
Password = "djdog"
ActiveSheet.Unprotect Password
Cells.Select
Selection.EntireRow.Hidden = False
Application.Goto Reference:=Range("A7"), Scroll:=True


Cheers

Pete
 
M

Mark Lincoln

Public Sub Worksheet_Activate()
Application.ScreenUpdating = False
Password = "djdog"
ActiveSheet.Unprotect Password
Cells.Select
Selection.EntireRow.Hidden = False
Application.Goto Reference:=Range("A7"), Scroll:=True

Peter, I don't know for sure, but I'd think turning off ScreenUpdating
is keeping your original code from working. I've never needed to keep
the screen from updating while using my code. Norman's code forces the
scrolling where your original code (and mine) do not.
 

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