+ Reply to Thread
Results 1 to 5 of 5

Locking cells after data entry on protected sheet / book

Hybrid View

  1. #1
    Registered User
    Join Date
    11-10-2011
    Location
    East Bangor, Pennsylvania
    MS-Off Ver
    Excel 2003
    Posts
    25

    Locking cells after data entry on protected sheet / book

    I am looking for a way to lock specific cells (namely X7, Y7, and range AD6:AD12) on attached file. The workbook and all worksheets are already locked, but I'm looking to protect some manually entered data. There are 65 sheets in the full workbook and if possible I'd like to only protect the current sheet once the data has been entered, not all of the sheets within the workbook.
    Any help is appreciated.
    Thanks
    Attached Files Attached Files

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: Locking cells after data entry on protected sheet / book

    You'll need to put this code on every sheet. Normally, using select is a bad idea in VB, but so is merged cells. I had to select the target to select all the merged cells, and then work on the selection.

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Intersect(Target, Range("Y7,Z7,AD6:AD12")) Is Nothing Then Exit Sub
    
    ActiveSheet.Unprotect Password:="LTW"
    Target.Select
    Selection.Locked = True
    ActiveSheet.Protect Password:="LTW"
    
    
    End Sub
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Registered User
    Join Date
    11-10-2011
    Location
    East Bangor, Pennsylvania
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Locking cells after data entry on protected sheet / book

    Thank you, this is definitely a start. Is it possible to tweak this a little bit and make it assignable code? Rather than it always checking for an entry, could it be written so that it could be assigned to a button? When the operator enters the necessary data they could click the button which would then lock those cells.

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: Locking cells after data entry on protected sheet / book

    If you want to do this manually, then do not put code on the sheets. Instead put this code in a regular module
    Sub LockIt()
    ActiveSheet.Unprotect Password:="LTW"
    Range("Y7:Z9,AD6:AE12").Locked = True
    ActiveSheet.Protect Password:="LTW"
    End Sub
    This code works on whatever sheet is active. You can either put a button on each sheet (yuck) or you can map the macro to a CTRL key such as CTRL-L.

  5. #5
    Registered User
    Join Date
    11-10-2011
    Location
    East Bangor, Pennsylvania
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Locking cells after data entry on protected sheet / book

    Thank you for both options. They both work well and I can use either. I see what you mean by the bad idea for merged cells in this instance (I had to tweak the range to read X7:Z12,AD6:AE12 in order to lock the required cells because X7-X12 are merged without getting an error message). I can definitely hit the ground running now with them.

+ 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. Need Help With Locking Formula in Protected Sheet
    By jmrlifesafe in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-01-2016, 01:30 PM
  2. Locking Cells After Data Entry Into A Template
    By KerryFreeman in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-23-2013, 06:48 PM
  3. Replies: 1
    Last Post: 06-21-2012, 07:07 AM
  4. Pasting outside data into unlocked cell of protected sheet without the cell locking
    By DarthMinogue in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-15-2011, 09:12 PM
  5. Data order entry in protected sheet
    By BRISBANEBOB in forum Excel General
    Replies: 4
    Last Post: 11-20-2010, 08:20 PM
  6. Only allow locking of cells in a protected sheet
    By zarniuup in forum Excel General
    Replies: 2
    Last Post: 08-30-2010, 02:53 PM
  7. Locking Cells after Entry
    By faisal.ta in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 05-21-2010, 12:56 PM

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