Results 1 to 2 of 2

Thread: Lock Cells after date passed - VBA Code

  1. #1
    Junior Member
    Join Date
    Apr 2015
    Posts
    1
    Rep Power
    0

    Lock Cells after date passed - VBA Code

    Hi,

    Please can you advise?

    I'm still very much a novice to VBA coding and would like some help before I lose all my hair for good

    I'm trying to allow staff to enter text into merge cells, and once the deadline date has passed it will auto lock these cells so editing cannot be done (audit purposes). I want to do this so it works on a month to month, though my code below only allows for Jan 2015.

    Below is the code I'm using but I feel all my ranges aren't quite right

    Code:
    Private Sub Workbook_Open()
        
        Dim wksTarget       As Worksheet
        Dim rngDate         As Range
        Dim rngData         As Range
        Dim c               As Long
        Dim LastRow         As Long
        Dim LastCol         As Long
        
        Const craig           As String = "craig" '<<  adjust to suit
        
        Set wksTarget = ThisWorkbook.Worksheets("Consents") '<<  adjust to suit
        
        If Not blnUnlockedAllCells Then
            wksTarget.Protect Password:=craig, userinterfaceonly:=True
            wksTarget.Cells.Locked = False
            blnUnlockedAllCells = True
        End If
        
        Set rngData = wksTarget.Range("C7:M14") '<<  adjust to suit. range including the date row
        
        For c = 7 To rngData.Columns.Count
            If CDate(rngData(7, c)) <= Date - 2 Then
                On Error Resume Next
                rngData.Columns(c).SpecialCells(8).Locked = True
                On Error GoTo 0
            End If
        Next
        
    End Sub
    I've attached the sheet to give you a better look into what I am trying to do.

    Thanks for you help in advance.
    Attached Files Attached Files

  2. #2
    Member p45cal's Avatar
    Join Date
    Oct 2013
    Posts
    94
    Rep Power
    12
    already self-resolved, see cross post: Lock Cells after date passed - VBA Code

Similar Threads

  1. Replies: 11
    Last Post: 10-25-2013, 11:03 PM
  2. Replies: 4
    Last Post: 08-20-2013, 06:28 PM
  3. Lock Cells After Data Entered
    By Admin in forum Excel and VBA Tips and Tricks
    Replies: 4
    Last Post: 06-28-2013, 10:52 PM
  4. Date References to save files using VBA Code
    By mrmmickle1 in forum Excel Help
    Replies: 3
    Last Post: 11-28-2012, 05:48 PM
  5. Lock cells on the basis of date VBA
    By Rajesh Kr Joshi in forum Excel Help
    Replies: 22
    Last Post: 09-27-2011, 03:56 PM

Posting Permissions

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