PDA

View Full Version : Solved: Limiting scroll area is preventing me from clicking any row buttons



frank_m
12-15-2011, 06:09 AM
Attached sample Workbook

The code I'm using to limit the scrolling range is preventing an entire row from being selected.
Is there anyway to re-write it so that I can select a row?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Call LimitScrollArea
End Sub

Private Sub CommandButton1_Click()
Call ResetScrollArea
End Sub

' in a regular module
Sub LimitScrollArea()
Dim LastRow As Long
With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
.ScrollArea = Range(Cells(1, 1), Cells(LastRow, 19)).Address
End With
End Sub

' in a regular module
Sub ResetScrollArea()
ActiveSheet.ScrollArea = ""
End Sub

Wish I could do something like this
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Call ResetScrollArea
If Not Me.RowButton.Clicked Then' incorrect syntax to demonstrate
Call LimitScrollArea
End If
End Sub

Aflatoon
12-15-2011, 06:25 AM
Perhaps something like:
If selection.rows(1).columns.count < me.columns.count Then

frank_m
12-15-2011, 06:42 AM
HI Aflatoon,

Thanks for your attention.

Sorry, but could you lead me a little further as to how to implement that ?

I tried this below and other variations but have not found success
.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Call ResetScrollArea

If Selection.Rows(1).Columns.Count < Me.Columns.Count Then

Call LimitScrollArea

End If

End Sub

Aflatoon
12-15-2011, 06:52 AM
My apologies, I was not really thinking clearly - that will not work, since the selection has not actually changed.
I cannot think offhand of how to do this.

frank_m
12-15-2011, 02:44 PM
Revised Sample workbook attached

I'd pieced together a work around that while it is not great,
it is very satisfactory for my requirement, so thought I would share just incase anyone finds it useful..

It does not limit scrolling using the scroll arrow on the Excel window,
but does limit the scroll range when scrolling while changing the selected cell using the keyboard right arrow key.

And, I can now select a Row, or column, as long as the activecell is in a column, that is less than #11
(11 can be changed, it's just in my case the viewable columns)

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim LastRow As Long
With ActiveSheet

If ActiveCell.Column > 10 Then

'''''''''''''''''''''''''''''''''''''''''''''''''
ActiveWindow.ScrollColumn = ActiveCell.Column - 1
'keeps in view as many columns as possible, that are to the right of the selected cell
'''''''''''''''''''''''''''''''''''''''''''''''''

LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
.ScrollArea = Range(Cells(1, 1), Cells(LastRow, 39)).Address
Else
.ScrollArea = ""

End If

End With

End Sub