Results 1 to 4 of 4

Thread: Protect only some cells on an Excel spreadsheet *RESOLVED*

  1. #1

    Thread Starter
    Hyperactive Member Simon Caiger's Avatar
    Join Date
    Aug 2000
    Location
    Rugby, England
    Posts
    377

    Protect only some cells on an Excel spreadsheet *RESOLVED*

    Hi,
    Is it possible to protect just certain cells on an Excel spreadsheet?
    I need to prevent the user from accidentally entering data into certain columns unless they have entered a password.
    I'm OK with the password entry bit.
    The code I have so far is:
    VB Code:
    1. Private Sub cmdLockA_Click()
    2.  
    3.     Sheet1.Range("A:A").Locked = True
    4.     Sheet1.Protect
    5.    
    6. End Sub
    7.  
    8. Private Sub cmdUnlockA_Click()
    9.  
    10.     frmPasswordColumnA.Show
    11.     If sColumAPasswordEntered = "Sossij" Then
    12.         Sheet1.Unprotect
    13.         Sheet1.Range("A:A").Locked = False
    14.     End If
    15.    
    16. End Sub
    The test code above is supposed to just prevent data entry to column A.
    Unfortunately, it seems to protect the whole sheet.

    Any help would be appreciated.
    Last edited by Simon Caiger; Feb 27th, 2004 at 09:33 AM.
    Simon Caiger

    Documentation is like sex; when it's good, it's very, very good, and when it's bad, it's better than nothing.

  2. #2
    Addicted Member
    Join Date
    Aug 2002
    Location
    Luton, UK
    Posts
    178
    I think you have missed the point that all cells in a worksheet are locked by default, so you first need to unlock them all, then lock your special cells.
    Sheet1.Cells.Locked = False ..............
    Regards
    BrianB
    -------------------------------

  3. #3
    Junior Member
    Join Date
    Mar 2003
    Location
    Mt. Holly, NJ
    Posts
    31
    Hey there,

    OK, all you need to do is unprotect your sheet. Select those cells you don't want protected, right click (or select from the menu) Format Cells.

    The last tab should be protection. All cells are by default Locked. Simply uncheck the locked box for those cells you don't want locked. Then reprotect your sheet.

    Peace!
    Josh

  4. #4

    Thread Starter
    Hyperactive Member Simon Caiger's Avatar
    Join Date
    Aug 2000
    Location
    Rugby, England
    Posts
    377
    Thanks for the replies,

    I do VBA very infrequently as you probaly noticed.

    I had missed the point that the cells are locked by default.
    I ended up doing this a different way but I will go back and give it a try the proper way.
    Simon Caiger

    Documentation is like sex; when it's good, it's very, very good, and when it's bad, it's better than nothing.

Posting Permissions

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



Click Here to Expand Forum to Full Width