OzGrid

How to scroll worksheet to see last row in selection

< Back to Search results

 Category: [Excel]  Demo Available 

How to scroll worksheet to see last row in selection

 

Requirement:

 

The user needs to have VBA scroll the worksheet so that last row of current selection is in view.


Example: If I have range C6:F500 selected I'd want that last row 500 in view, another time it may be C6:F200, so I'd want that last row 200 in view

 

1. The user needs it to just scroll to last row in existing selection, not to make a different selection by selecting last cell, i.e. to keep existing selection which was also copied to clipboard before your proposed code
E.g.: if range C6:F300 is the current selection the user only needs the code to scroll down to make that last row 300 visible, not to make any new selections, but do keep original selection copied
2. Don't need it to scroll columns, only rows. Removing Selection.Columns.Count did not prevent scrolling of columns but prevented selecting cell in last row, instead selected cells seemingly at random mid current selection.

 

The user doesn't want it to select anything.


The user needs it to leave current selected range as is.


The user needs it to only scroll to the last row of that already selected range.

 

Solution:

 

Code:
Dim lRw As Long
lRw = Selection.Cells(Selection.Rows.Count, Selection.Columns.Count).Row
ActiveWindow.ScrollRow = lRw

 

Obtained from the OzGrid Help Forum.

Solution provided by royUK.

 

See also: Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions and Index to new resources and reference sheets

 

See also:

How to compare two columns in excel, inserting blank rows moving associated data
How to add rows and specific text after changes in data
How to highlight selected cell in row 1 only
How to delete row if Date/Time between 05:00 - 20:00

 

Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.


Gallery



stars (0 Reviews)