+ Reply to Thread
Results 1 to 5 of 5

Lock whole sheet after a specific date

  1. #1
    Forum Contributor
    Join Date
    01-25-2021
    Location
    Atlanta, Georgia
    MS-Off Ver
    365
    Posts
    144

    Lock whole sheet after a specific date

    I have a workbook with tabs representing each month of the year. On a given month, staff are allowed to enter information in specific columns housed inside a table. They have until the 5th of following month to enter their info. Each sheet is protected and have both locked and unlocked cells. I would like to make the unlocked cells (really all cells) locked on the 6th of following month. The date of month is in A1 of each tab (January = 1/1/22, February 2/1/22).

    Anything with *** I am not sure of the correct code:
    Sheet1.Select
    Sheet1.Unprotect "$$$"
    Sheet1.ListObjects("Table1").Range.Select
    ***If NOW() is 1 month and 6 days after date listed in A1, then protect all cells in Table1
    Sheet1.Select
    Sheet1.Protect "$$$"

  2. #2
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,444

    Re: Lock whole sheet after a specific date

    Hi,

    This should do what you need.

    Please Login or Register  to view this content.
    To execute it automatically, one way would be to call it from the workbook open event in the workbook object

    Please Login or Register  to view this content.
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  3. #3
    Forum Contributor
    Join Date
    01-25-2021
    Location
    Atlanta, Georgia
    MS-Off Ver
    365
    Posts
    144

    Re: Lock whole sheet after a specific date

    Thanks Sweep. I modified your code slightly to indicate expiration date as one month AND five days added to "A1" but doesn't seem to work. Can you ID my error please:

    Private Sub Workbook_Open()
    Call Check_Expired
    End Sub

    Sub Check_Expired()
    Dim sh As Worksheet
    Dim dExpiry As Date

    For Each sh In ThisWorkbook.Sheets
    sh.Unprotect Password:="password"
    dExpiry = DateSerial(Year(A1), Month(A1) + 1, Day(A1) + 5)
    If dExpiry <= DateValue(Now) Then
    sh.Cells.Locked = True
    End If
    sh.Protect Password:="password"

    Next sh


    End Sub

  4. #4
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,444

    Re: Lock whole sheet after a specific date

    Hi,

    Your code is looking at a variable, A1 rather than the contents of cell A1..

    Change this...
    Please Login or Register  to view this content.
    for this.....
    Please Login or Register  to view this content.
    Last edited by sweep; 02-11-2022 at 05:35 AM.

  5. #5
    Forum Contributor
    Join Date
    01-25-2021
    Location
    Atlanta, Georgia
    MS-Off Ver
    365
    Posts
    144

    Re: Lock whole sheet after a specific date

    Thanks Sweep

+ 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 to lock a sheet within a workbook after specific date
    By hewcarroll in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-28-2017, 01:17 PM
  2. lock/unlock specific cell in a password protected sheet
    By Opi in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 3
    Last Post: 03-01-2016, 04:43 AM
  3. Lock Specific Shape on a Sheet Keeping all other elements unlocked
    By asgharhussaini in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-10-2015, 08:29 PM
  4. [SOLVED] Lock Sheet (With specific settings..)
    By jcabroxo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-21-2015, 12:10 PM
  5. Set range of cells in multiple sheets to lock after a specific date
    By miasha in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-07-2014, 07:33 PM
  6. Replies: 3
    Last Post: 06-30-2010, 09:46 AM
  7. Lock sheet tabs option in a specific workbook
    By Tarique in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-08-2006, 11:55 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