Unable to lock the cell based on current date

dd08

New Member
Joined
May 15, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hi experts, I am bit new to VBA macros .
I have made one daily attendance sheet, where in entered value to be locked once current date is passed. Values are getting selected from drop down.

code i have used


Private Sub worksheet_Change(ByVal Target As Range)



Dim col As Range



With ThisWorkbook.Sheets("Sheet1")

.Unprotect "123"

For Each col In .UsedRange.Columns

col.EntireColumn.Locked = col.Range("C7").Value < Date

Next col

.Protect "123"

.EnableSelection = xlNoRestrictions

End With

End Sub


My requirement- user will select status on daily basis and once day is over user wont be able to change entered status.
 

Attachments

  • Capture1.JPG
    Capture1.JPG
    84 KB · Views: 9

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Will this work for you
VBA Code:
Private Sub worksheet_Change(ByVal Target As Range)
Dim rng As Range
Dim row As Range
Dim cell As Range
Set rng = Range("C7:R7")
With ThisWorkbook.Sheets("Sheet1")

For Each row In rng.Rows
.Unprotect "123"
  For Each cell In row.Cells
   If cell.Value < Date Then
ActiveSheet.Columns(cell.Column).Locked = True
   End If
  Next cell

Next row

.Protect "123"

End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,737
Messages
6,132,436
Members
449,727
Latest member
Aby2024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top