Consulting

Results 1 to 9 of 9

Thread: Solved: worksheet scrolling

  1. #1

    Solved: worksheet scrolling

    hi all,
    if i wanted the user to be able to only scroll thru a range (say c5:f15) of a particular worksheet, is there a method to do that? i am using 2007 and 2003 vba. if there is a method, are there any particular negatives to doing so?
    thank you.

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Hi there,

    As that's a pretty small range, when you say "scroll", do you actually mean scroll with the scrollbar, or limit the user to selecting cells in the aforementioned range?

    Mark

  3. #3
    the range size is something i just made up.
    looking at my workbook (on a friday night......) it would really be b21:j34
    i would be interested in info on both of your queries. if i had to pick, i would say limit the selection to only that range.
    erik

  4. #4
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Hi Erik,

    In a blank/new workbook, place this in the ThisWorkbook Module.
    [vba]
    Option Explicit

    Private Sub Workbook_Open()
    Sheet1.ScrollArea = "A1:Z100"
    With Sheet2
    With .Range("B2:J20")
    .Interior.ColorIndex = 6
    .Locked = False
    End With
    .Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
    .EnableSelection = xlUnlockedCells
    End With
    End Sub
    [/vba]

    After saving and closing the wb, when you reopen it, you will only be able to scroll in the designated area on Sheet1, and Sheet2 will only allow the user to select unprotected cells.

    Mark

  5. #5
    Would any of these do?

    If you want it to apply to a specific worksheet
    Private Sub Worksheet_Activate() 
        Me.ScrollArea = "A1:BS46" 
    End Sub
    If you're always opening it at the sheet you want to restrict the scroll area on use (in the ThisWorkbook module)
    Option Explicit 
    Private Sub Workbook_Open() 
        ActiveSheet.ScrollArea = "A1:BS46" 
    End Sub
    if you want the restricted area to apply to every worksheet use (in the ThisWorkbook module)
    Private Sub Workbook_SheetActivate(ByVal Sh As Object) 
        ActiveSheet.ScrollArea = "A1:BS46" 
    End Sub

  6. #6
    thank you all for the info.
    erik

  7. #7
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    For entering data in restricted columns I use this.
    Select cols 1-3 and run SetScroll. To restore, select a single cell and run SetScroll

    [vba]
    Sub SetScroll()
    If Selection.Cells.Count = 1 Then
    ActiveSheet.ScrollArea = Cells.Address
    Application.MoveAfterReturnDirection = xlDown
    Else
    ActiveSheet.ScrollArea = Selection.Address
    Application.MoveAfterReturnDirection = xlToRight
    End If
    End Sub
    [/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  8. #8
    VBAX Regular arkusM's Avatar
    Joined
    May 2007
    Location
    Calgary
    Posts
    52
    Location
    With out using Code you can just set the properties of the sheet using VBA editor set the .ScrollArea manually to the b21:j34. If you don't have any other code on the workbook, and it will not trigger a Macro Warning.
    Old School, hard coded and not elegant but an option.
    Excel 2003, WinXP

  9. #9
    wow, i like the setscroll sub!
    thanks again for all your help.
    erik

Posting Permissions

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