When working in Excel, there are times when you want to display a specific cell exactly at the top-left corner of the screen. For example, you might want to instantly jump to a row in the middle of a data list and start working from there.
The ScrollRow and ScrollColumn properties of the ActiveWindow object are very useful for this purpose. By combining these two, you can move any cell to the top-left position of the window.
Basic Code: Displaying a Cell at the Top-Left
Dim targetCell As Range
Set targetCell = Range("M30")
With ActiveWindow
.ScrollRow = targetCell.Row
.ScrollColumn = targetCell.Column
End With
Code Explanation
Range("M30"): Specifies the cell you want to display at the top-left (M30 in this example)..ScrollRow = targetCell.Row: Sets the row number of the specified cell as the top row of the screen..ScrollColumn = targetCell.Column: Sets the column number of the specified cell as the leftmost column of the screen.
When you run this code, cell M30 will be displayed right at the top-left corner of the screen.
Advanced Example: Scrolling and Selecting the Cell
If you want to scroll the cell to the top-left and also select it, add the .Select method.
Dim baseCell As Range
Set baseCell = Range("H20")
With ActiveWindow
.ScrollRow = baseCell.Row
.ScrollColumn = baseCell.Column
End With
baseCell.Select
This code moves the view so that cell H20 is at the top-left and then selects that cell.
Important Notes
- Screen Movement: Since this operation scrolls the screen, it changes the user’s view. If the user is in the middle of a task, it is polite to notify them beforehand or use it carefully.
- Hidden Cells: If the specified cell (or its row/column) is hidden, the scrolling may not work correctly.
- Frozen Panes: If you have used “Freeze Panes,” the scrolling might not position the cell exactly where you expect (it will scroll the scrollable area).
Use Cases
- Input Forms: Automatically guiding the user to a specific input field.
- Data Lists: Jumping to a specific section in a long list.
- Error Handling: Moving an error cell to the top-left to highlight it for the user.
Summary
| Goal | Code |
| Scroll to Top-Left | .ScrollRow = Range.Row and .ScrollColumn = Range.Column |
| Scroll + Select | Add .Select after scrolling |
By using ScrollRow and ScrollColumn, you can clearly show users which cell they should focus on. This is highly useful for improving visibility and work efficiency, especially in form controls and data reviews.
