Consulting

Results 1 to 5 of 5

Thread: Solved: Limiting scroll area is preventing me from clicking any row buttons

  1. #1
    VBAX Expert
    Joined
    Sep 2010
    Posts
    604
    Location

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

    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?
    [vba]
    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
    [/vba]
    Wish I could do something like this
    [vba]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[/vba]
    Attached Files Attached Files

  2. #2
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    Perhaps something like:
    [vba]If selection.rows(1).columns.count < me.columns.count Then[/vba]
    Be as you wish to seem

  3. #3
    VBAX Expert
    Joined
    Sep 2010
    Posts
    604
    Location
    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
    .[VBA]
    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

    [/VBA]

  4. #4
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    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.
    Be as you wish to seem

  5. #5
    VBAX Expert
    Joined
    Sep 2010
    Posts
    604
    Location
    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)
    [vba]
    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
    [/vba]
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •