+ Reply to Thread
Results 1 to 9 of 9

Auto Lock Cells once data is entered not working.

  1. #1
    Registered User
    Join Date
    08-12-2014
    Location
    UAE
    MS-Off Ver
    7
    Posts
    10

    Auto Lock Cells once data is entered not working.

    Hi all, first time posting.

    I have searched and found many examples of code that will lock cells once data has been entered. But for some reason, I cannot get it to work in my workbook. The weird thing is, I have successfully got them to work on blank workbooks. I unlock a range I want people to be able to edit, I protect the workbook, I enter the code, and it works. But I do the same thing on my workbook, nothing locks. Can anyone think of any possible reasons for this? I've tried locking all the cells on a sheet, and only unlocking a small range, as in the examples (A1:A10), and I cant get it to work. I've tried not pre-protecting the sheet, I've tried 4 or 5 different examples of code. If it wasn't for the fact I've gotten it to work on blank workbooks, I'd think VBA was disabled or something. I can't post a copy of my workbook for you all to look at because its on a stand-alone computer at work (and the USB is disabled for info-sec).

    When I hit 'View Code' on the sheet, and paste in the code, is there something else I need to do? It's almost as if the code is going in, but not running? I'm not a complete programming noob (did C++ back in the day), but VBA is new to me.

    Excel Version 2007

    Thanks
    Last edited by garyreid81; 08-15-2014 at 02:35 PM.

  2. #2
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: Auto Lock Cells once data is entered not working.

    As I read from your post your company maintains a pretty tough security policy.
    So did you check the default security setting of Excel?
    Specially the setting for macros. Maybe they are disabled.
    Cheers!
    Tsjallie




    --------
    If your problem is solved, pls mark the thread SOLVED (see Thread Tools in the menu above). Thank you!

    If you think design is an expensive waste of time, try doing without ...

  3. #3
    Registered User
    Join Date
    08-12-2014
    Location
    UAE
    MS-Off Ver
    7
    Posts
    10

    Re: Auto Lock Cells once data is entered not working.

    I thought that too, but why then can I get it to work on a blank workbook? Its got to be something in my workbook.

  4. #4
    Registered User
    Join Date
    08-15-2014
    Location
    India
    MS-Off Ver
    2007
    Posts
    57

    Re: Auto Lock Cells once data is entered not working.

    check the sheet name if its same as in the code

  5. #5
    Registered User
    Join Date
    08-12-2014
    Location
    UAE
    MS-Off Ver
    7
    Posts
    10

    Re: Auto Lock Cells once data is entered not working.

    Hey, I've tried that as well with certain examples of code that require the sheet name. I've also tried examples of code where no sheet name is entered.

  6. #6
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Auto Lock Cells once data is entered not working.

    To check if the code on worksheet module is running or not, open the code and remove Sub from End Sub (the last line of code) and comeback to your sheet and enter a value in the range specified in the code. If you get the Compile Error: Expected End Sub, that means your code is running, add the Sub after End in the last line and debug the code by pressing F8 to see what that code is exactly doing.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  7. #7
    Registered User
    Join Date
    08-15-2014
    Location
    India
    MS-Off Ver
    2007
    Posts
    57

    Re: Auto Lock Cells once data is entered not working.

    try this module (the only problem even if you press delete by mistake that cell will get locked)

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim MyRange As Range

    Set MyRange = Intersect(Range("A1:O1000"), Target)
    If Not MyRange Is Nothing Then
    Sheets("Sheet1").Unprotect Password:="1234"
    MyRange.Locked = True
    AllowFiltering = True
    Sheets("Sheet1").Protect Password:="1234"
    End If
    End Sub

  8. #8
    Registered User
    Join Date
    08-12-2014
    Location
    UAE
    MS-Off Ver
    7
    Posts
    10

    Re: Auto Lock Cells once data is entered not working.

    Hey, Thanks for the reply. I get the same thing with this.

    I tried something new. I have been working on a copy of my Workbook. Back when I started this, I briefly had it working, then lost it. So, I tried again, this time with a NEW copy of my workbook. It Worked! So I thought. I saved the file, closed it. Then re-opened it and it went back to not working. Any attempt to redo the code to lock a sheet, nothing. So, something happens when I close the workbook. It works initially, then once its closed, it completely fails. Even if I try to auto-lock a completely different sheet (there is a sheet for each day of the month), it wont work. Any ideas? Thanks for all the replies!

  9. #9
    Registered User
    Join Date
    08-12-2014
    Location
    UAE
    MS-Off Ver
    7
    Posts
    10

    Re: Auto Lock Cells once data is entered not working.

    OK, I think I figured it out. Went into the Macros Security on my work computer and compared to those on my personal computer. For some reason, on my work computer, "Enable all macros..." wasn't selected and also there was no check next to "Trust access to the VBA..." I assumed (wrongly) that saving a file as "Macro Enabled Excel Workbook" would in-turn enable all macros...Guess not!

    This was probably a dumb one on my part, but I've never used VBA. Thanks for all the help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Auto lock cells after data entered and SAVED
    By fedcco in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 07-26-2016, 07:40 AM
  2. auto-lock cells after time is entered so that it cannot be changed
    By VanHardy in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-16-2013, 05:19 PM
  3. automatically lock cells when data is entered
    By superchew in forum Excel General
    Replies: 12
    Last Post: 05-20-2013, 02:46 AM
  4. Auto-lock a row after data is entered
    By src16 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-25-2013, 09:50 AM
  5. How to auto lock a cell once data is entered
    By infonaurvind in forum Excel General
    Replies: 1
    Last Post: 06-08-2012, 06:57 AM

Tags for this Thread

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