Consulting

Results 1 to 6 of 6

Thread: Limit Scroll area on open

  1. #1

    Limit Scroll area on open

    I have the following simple code that limits the scroll area. However, upon opening the workbook, the scroll area is not limited until the user clicks on a cell. Anyway to make execute it on open?

    Thanks.

    -ep

     
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Me.ScrollArea = "A1:BS46"
    End Sub

  2. #2
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    [VBA]Private Sub Worksheet_Activate()
    Me.ScrollArea = "A1:BS46"
    End Sub[/VBA]
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  3. #3
    Still not working. When I open the workbook I can go directly to the scroll bar and scroll outside the limit. Am I doing something wrong?

    -ep

  4. #4
    VBAX Mentor asingh's Avatar
    Joined
    Jul 2005
    Posts
    307
    Location
    Give this a try......put the code in you workbook open event. If you want to execute on all the sheet..just loop through each sheet in you workbook.

    [VBA][/VBA]
    Private Sub Workbook_Open()
    Dim ws As Worksheet

    Set ws = ActiveSheet

    ws.ScrollArea = "A1:BS46"

    Set ws = Nothing

    End Sub

    [VBA][/VBA]

  5. #5
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    If you're always opening it at the sheet you want to restrict the scroll area on use (in the ThisWorkbook module)
    [VBA]Option Explicit
    Private Sub Workbook_Open()
    ActiveSheet.ScrollArea = "A1:BS46"
    End Sub[/VBA]
    if you want the restricted area to apply to every worksheet use (in the ThisWorkbook module)
    [VBA]
    Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    ActiveSheet.ScrollArea = "A1:BS46"
    End Sub
    [/VBA]
    If you want it to apply to a specific worksheet use what I gave you previously in the worksheet module
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  6. #6
    VBAX Newbie
    Joined
    Oct 2006
    Posts
    1
    Location

    Smile

    This works well except for a couple of issues. I see a highlited/outlined box around the 1st cell in the area no matter what I do. If I create a custom view then scrollarea is disabled. I can't get rid of this box, any ideas? I've seen a link that works for forms in Access, but nothing for Excel. Is there any way to disable the scroll wheel in Excel(that would be the best)?

    Thanx in advance - Dean

Posting Permissions

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