+ Reply to Thread
Results 1 to 16 of 16

Auto locking cells

Hybrid View

  1. #1
    Spammer
    Join Date
    01-09-2011
    Location
    Colombo
    MS-Off Ver
    Excel 2007
    Posts
    116

    Auto locking cells

    I have created a shared workbook to update certain entries by my colleagues. I have noticed that some of the entries were deleted after some time. I want to know if I can share the work with the following feature:-

    As soon as somebody enters data to a cell, it should be automatically locked and should not allow anyone to delete or edit the cell.

    How do I do it? Please help me. Thanks in advance.
    Last edited by mifzal.mufthi; 04-29-2013 at 12:56 PM.

  2. #2
    Spammer
    Join Date
    01-09-2011
    Location
    Colombo
    MS-Off Ver
    Excel 2007
    Posts
    116

    Re: Auto locking cells

    Help me please

  3. #3
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Auto locking cells

    You can't use sheet protection when the file is in shared mode


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  4. #4
    Spammer
    Join Date
    01-09-2011
    Location
    Colombo
    MS-Off Ver
    Excel 2007
    Posts
    116

    Re: Auto locking cells

    Quote Originally Posted by :) Sixthsense :) View Post
    You can't use sheet protection when the file is in shared mode
    Thanks but I don't think you have understood the question. I know that protection cannot be enabled while on sharing mode. I know how to enable protection too. What my question is, how do I protect cells as soon as I enter a data? The purpose of doing that is to prevent deleting or modifying data. Once a data is entered, it should automatically lock the cell. How do I do that?

  5. #5
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Auto locking cells

    Again, protecting the cell content can't be done without using the sheet protection

  6. #6
    Spammer
    Join Date
    01-09-2011
    Location
    Colombo
    MS-Off Ver
    Excel 2007
    Posts
    116

    Re: Auto locking cells

    Quote Originally Posted by :) Sixthsense :) View Post
    Again, protecting the cell content can't be done without using the sheet protection
    READ MY ENGLISH. I know how to protect worksheet. I am expecting a solution to my question

  7. #7
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Auto locking cells

    Quote Originally Posted by mifzal.mufthi View Post
    READ MY ENGLISH. I know how to protect worksheet. I am expecting a solution to my question
    IS THIS IN ENGLISH??? And as you expect a solution to your question and we MUST(we had to.) give a solution...

    http://chandoo.org/forums/topic/lock...-entry-in-cell
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  8. #8
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Auto locking cells

    Quote Originally Posted by mifzal.mufthi View Post
    READ MY ENGLISH. I know how to protect worksheet. I am expecting a solution to my question
    if you formulate your request, more politely, be sure that you'll find your solution..

  9. #9
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Auto locking cells

    perhaps you could read your own statement
    I know that protection cannot be enabled while on sharing mode.
    but then
    how do I protect cells as soon as I enter a data?
    the answer is clear as you have already outlined-do not use sharing mode. if you must use sharing mode you cannot change the protection of cells
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  10. #10
    Spammer
    Join Date
    01-09-2011
    Location
    Colombo
    MS-Off Ver
    Excel 2007
    Posts
    116

    Re: Auto locking cells

    Quote Originally Posted by JosephP View Post
    perhaps you could read your own statement

    but then


    the answer is clear as you have already outlined-do not use sharing mode. if you must use sharing mode you cannot change the protection of cells
    I have removed the sharing. Now, how do I accomplish my task?

  11. #11
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Auto locking cells

    right click the worksheet tab choose view code then paste in this code
    Private Sub Worksheet_Change(ByVal Target As Range)
        Const csPASSWORD As String = "your password here"
        Dim rCell As Range
        Me.Unprotect Password:=csPASSWORD
        For Each rCell In Target.Cells
            If Len(rCell.Formula) > 0 Then rCell.Locked = True
        Next rCell
        Me.Protect Password:=csPASSWORD
    End Sub
    finally I suggest you read your posts again and try and see how they appear to others-it may encourage you to adopt a different tone with the people you want to help you ;-)

  12. #12
    Spammer
    Join Date
    01-09-2011
    Location
    Colombo
    MS-Off Ver
    Excel 2007
    Posts
    116

    Re: Auto locking cells

    Quote Originally Posted by JosephP View Post
    right click the worksheet tab choose view code then paste in this code
    Private Sub Worksheet_Change(ByVal Target As Range)
        Const csPASSWORD As String = "your password here"
        Dim rCell As Range
        Me.Unprotect Password:=csPASSWORD
        For Each rCell In Target.Cells
            If Len(rCell.Formula) > 0 Then rCell.Locked = True
        Next rCell
        Me.Protect Password:=csPASSWORD
    End Sub
    finally I suggest you read your posts again and try and see how they appear to others-it may encourage you to adopt a different tone with the people you want to help you ;-)
    Thanks buddy. It worked only once. I mean, only 1 entry is allowed and it locks automatically. I should be able to enter so many entries and as we enter entries, they should be locked. Thanks for your effort again. Please refer the attached
    Attached Files Attached Files

  13. #13
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Auto locking cells

    you need to unlock all the cells you want the user to be able to change before you start-Locked is the default setting

  14. #14
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,251

    Re: Auto locking cells

    An alternative approach without using sheet protection. It *may* work for you and may even work in a shared workbook ... but no guarantees.

    It uses Worksheet_SelectionChange to monitor the cells. Once data has been entered, you cannot select the cell(s) again. It "homes" to cell A1 if a completed cell is selected. You could limit the range that is monitored and you could pick a different cell to home to. However, you do need to move away from the selected cell.

    Option Explicit
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    Dim cell As Range
    Dim bDataPresent As Boolean
    bDataPresent = False
    For Each cell In Target
        If cell.Value <> "" Then
            bDataPresent = True
            MsgBox "you cannot edit cell " & cell.Address
        End If
    Next ' cell
    If bDataPresent Then
        Application.EnableEvents = False
        Range("A1").Select
        Application.EnableEvents = True
    End If
    End Sub

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


+ 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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1