Results 1 to 10 of 23

Thread: Lock cells on the basis of date VBA

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    Grand Master
    Join Date
    Apr 2011
    Posts
    22
    Rep Power
    10
    Code:
        Dim wksTarget           As Worksheet
        Dim rngDate             As Range
        Dim rngData             As Range
        Dim c                   As Long
        Dim LastRow             As Long
        Dim LastCol             As Long
        Dim blnUnlockedAllCells As Boolean
        
        Const Pwd               As String = "pwd" '<<  adjust to suit
        
        Set wksTarget = ThisWorkbook.Worksheets("Sheet2") '<<  adjust to suit
        
        If Not blnUnlockedAllCells Then
            wksTarget.Protect Password:=Pwd, userinterfaceonly:=True
            wksTarget.Cells.Locked = False
            blnUnlockedAllCells = True
        End If
        
        Set rngData = wksTarget.Range("B3:L16") '<<  adjust to suit. range including the date row
        
        For c = 1 To rngData.Rows.Count
            If CDate(rngData(c, 1)) <= Date - 2 Then
                On Error Resume Next
                rngData.Rows(c).SpecialCells(2).Locked = True
                On Error GoTo 0
            End If
        Next
    Attached Files Attached Files
    Last edited by S M C; 09-11-2011 at 07:49 PM.

Similar Threads

  1. 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
  2. Help- Locking column basis current date.
    By Rajesh Kr Joshi in forum Excel Help
    Replies: 1
    Last Post: 03-25-2013, 04:44 PM
  3. automatic Add date in cells
    By Ryan_Bernal in forum Excel Help
    Replies: 1
    Last Post: 01-23-2013, 02:50 PM
  4. How to Lock or Unlock row basis previous cell input?
    By Rajesh Kr Joshi in forum Excel Help
    Replies: 2
    Last Post: 07-25-2012, 02:40 PM
  5. Count no of cells containing date
    By princ_wns in forum Excel Help
    Replies: 5
    Last Post: 04-16-2012, 10:37 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
  •