Link to home
Start Free TrialLog in
Avatar of Omar Khaled
Omar Khaled

asked on

VBA to scroll down and up and to top

Can we make the macro first time I press it, to go from a1 to a102 and then after that it goes every 100 rows so next would be 202, 302 and so on.
Can you provide a macro to do the opposite? to go up 100 rows? and a macro to go to the top
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you mean Select or Activate then this is not usually necessary. What are you actually doing?

 For example, this will enter "Hello World" in  rows 302,202,102,2 of Column A without actually "going" to them.

   
Dim lrw As Long
    For lrw = 302 To 1 Step -100
        Cells(lrw, 1).Value = "Hello World"
    Next lrw

Open in new window

Roy, From what I have understood from the question the asker wants to browse the sheet by the defined rows on single clicks and avoid manual browsing.
I'm not sure , but if Omar does want to that I would use

 
Sub MoveRows()
    With Selection
        If .Row <= 2 Or .CountLarge > 1 Then
            MsgBox "Last Row reached.", vbCritical, "Quitting"
            Exit Sub
        End If
        Application.Goto .Offset(-100)
    End With
End Sub

Open in new window

To go to top left of screen just press Ctrl + Home key.

For going to top and bottom of a column there is no need for VBA.

For top/bottom of column, press Ctrl + Space to select whole column, pressing Ctrl & . (decimal/period/fullstop) will then toggle between first and last cell of selected range. This actually works for more than one column or a selected range if required, it will rotate the active cell from top left, top right, bottom right, bottom left and back to top left.

You can also use the F5 key to go to specific cell/range. Press F5 and type A100 and enter, the cursor will go to cell A100.
Avatar of Omar Khaled
Omar Khaled

ASKER

Thank you guys. Sorry for the delay in closing the question. I was out of the country with no connections. Thanks again for the help.
You’re welcome and I’m glad I was able to help.

If you expand the “Full Biography” section of my profile you’ll find links to some articles I’ve written that may interest you.

Marty - Microsoft MVP 2009 to 2017
              Experts Exchange Most Valuable Expert (MVE) 2015, 2017
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2017
              Experts Exchange Top Expert VBA (current)