+ Reply to Thread
Results 1 to 3 of 3

lock cells for edit through VBA

  1. #1
    Forum Expert icestationzbra's Avatar
    Join Date
    01-07-2004
    MS-Off Ver
    2007, 2010
    Posts
    1,418

    lock cells for edit through VBA

    hi,

    is there a way to lock certain cells for editing through a piece of VBA code?

    i have some data in cells D1:D100. i would like to prevent people from editing those cells, it could pop-up a message "cannot edit" or something like that.

    i tried using Target.AllowEdit = False in the SelectionChange event, it does not work. i do not want to use Protect Sheet from the Tools menu for some reasons.

    thanks in advance for any inputs,

    mac.

  2. #2
    Forum Expert icestationzbra's Avatar
    Join Date
    01-07-2004
    MS-Off Ver
    2007, 2010
    Posts
    1,418
    hi,

    could someone please help me with this problem?

    thanks,

    mac.

  3. #3
    Forum Contributor
    Join Date
    01-11-2004
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    388
    Hi!

    I note your aversion to sheet Protection.

    Would it be acceptable to set all cells to "Unlocked" and then apply sheet protection?

    I ask, because you could then apply local protection to selected cells either permanently (beforehand from the menu) or on a temporary basis using VBA to switch cell locking on and off.

    The sort of situation where I've used it involved locking cells to input if certain conditions applied (e.g. either put in the aggregate of two numbers or put in the 2 separately but don't allow mixing the methods).

    If (IsEmpty(rngL) = False) Or (IsEmpty(rngK) = False) Then ActiveSheet.Unprotect "password"
    rngK.Locked = False
    rngL.Locked = False
    rngM.Locked = True
    ActiveSheet.Protect password:="password"
    GoTo QuickExit
    End If

    Does anything in this rambling spark any inspirations?

    Alf

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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