Restricting Scroll Area

vba_monkey

Board Regular
Joined
Dec 18, 2013
Messages
112
Hello,

I can use this code to retrict the scroll area of a worksheet to the used range:

Code:
Sheets(1).ScrollArea = Range(Sheets(1).UsedRange, Sheets(1).UsedRange(2, 2)).Address

Say, for example the scroll area has been restricted to $A$1:$M$69. You can scroll down until row 69 is at the top of the sheet and is the only visible line with blank space beneath it.

I would like to restrict it so that the scroll stops when Row 69 is at the bottom of the sheet without exposing the empty space beneath. Does anyone know how to achieve this?

Thanks
 
Last edited:

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
i would just hide the remainder rows :)
 
Upvote 0
How about
Code:
Sub chk()
Sheets(1).ScrollArea = Range(Sheets(1).UsedRange.Rows, Sheets(1).UsedRange.Columns).Address
End Sub
 
Upvote 0
In that case it sounds like the usedrange is larger than expected.
one option might be
Code:
Sub chk()
Dim x
x = Sheets(1).UsedRange
Sheets(1).ScrollArea = Sheets(1).UsedRange.Address
End Sub
or
Code:
Sub chk()

    Dim UsdCols As Long
    Dim Usdrws As Long
    With Sheets(1)
        Usdrws = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        UsdCols = .Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).column
        .ScrollArea = .Range("A1", .Cells(Usdrws, UsdCols)).Address
    End With
End Sub
 
Upvote 0
Thanks, Fluff.

I've tried both your methods and they still produce the same result.

It looks like when the rows outside the used range are hidden, it produces the behavior I described and if they are unhidden it behaves how I want to. I may have to compromise and and keep them visible although it's not perfect.

I doubt there is a way around this but let me know if you think there is.
Ta
 
Upvote 0
Ok, how about
Code:
Sub chk()

    Dim UsdCols As Long
    Dim Usdrws As Long
    With Sheets(1)
        Usdrws = .UsedRange.SpecialCells(xlVisible).Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        UsdCols = .Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).column
        .ScrollArea = .Range("A1", .Cells(Usdrws, UsdCols)).Address
    End With
End Sub
 
Upvote 0
Still the same I'm afraid. All of these methods set the same scroll area, it's just the way excel behaves when you scroll down depends on whether the rows outside of the scroll area are hidden or not.
 
Upvote 0
I set some hidden rows, ~100 rows below my data & used the code in post#8 & I could not scroll below the last visible row.
When you try it what value does UsdRws have? & is it the last visible row?
If not you may have cells containing spaces or the like.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top