0

So I posted the following question yesterday:Link

and was able to write the following code to (kinda) solve it:

Sub LockDateCols()

Dim j As Range

Sheets("Sheet1").Unprotect
curdate = Int(CDbl(Now()))

For Each j In Sheets("Sheet1").Range("F6:As6").Cells
    If curdate > j.Value Then
        j.EntireColumn.Locked = False
    End If
Next j
Sheets("Sheet1").Protect
End Sub

This code locks the columns that have a date value GREATER than the current date and it needs to do the opposite but when I switch the greater than sign i get a Runtime 1004 error that says "unable to set the locked property of the range class"

I'm basically out of ideas, there are no merged ranges.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
DBA108642
  • 1,995
  • 1
  • 18
  • 55

1 Answers1

0

The following code works:

Sub LockDateCols()

Dim j As Range

Sheets("Proposed Baseline").Unprotect
curdate = Int(CDbl(Now()))

For Each j In Sheets("Proposed Baseline").Range("f6:As6").Cells
    If j.Value > curdate Then
        j.EntireColumn.Locked = False
    Else
        j.EntireColumn.Locked = True
    End If
Next j
Sheets("Proposed Baseline").Protect
End Sub

Instead of just trying to do it with one line I added an else statement and that seems to have done the trick.

DBA108642
  • 1,995
  • 1
  • 18
  • 55