Consulting

Results 1 to 4 of 4

Thread: VBA to lock specific rows when a worksheet opens

  1. #1
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location

    VBA to lock specific rows when a worksheet opens

    I'm trying to lock specific rows when a worksheet opens.
    This is the code that I have which is NOT working.
    Its selecting the rows, but, thats it.

    What am I doing wrong?

    Worksheets(MySht).Activate
    Rows(3).Select
    Selection.Locked = True
    Selection.FormulaHidden = False
    
    Rows(8).Select
    Selection.Locked = True
    Selection.FormulaHidden = False

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    With Worksheets(MySht)
     
    With .Rows(3)
    
    .Locked = True 
    .FormulaHidden = False 
    End With
    
    With .Rows(8)
    
    .Locked = True 
    .FormulaHidden = False
    End With
    
    .Protect
    End With
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,098
    Location
    Could you shorten this a bit more?
    With Worksheets(MySht)
    With .Rows(3:3,8:8)
    .Locked = True
    .FormulaHidden = False
    .Protect
    End With
    End With
    End Sub
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  4. #4
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location
    Solutions worked great.

    Thanks

Posting Permissions

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