Lock the particular cells after date is over

RAMU

Active Member
Joined
Dec 11, 2009
Messages
345
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
  2. Mobile
Hi Friends,

Hv a workbook with multiple sheets (months).

In july sheet I need these feature:

July

ABCDEFGHIJK
START FINISH
DATETIME DATETIME HOUR QTY

<colgroup><col style="WIDTH: 30px; FONT-WEIGHT: bold"><col style="WIDTH: 64px"><col style="WIDTH: 64px"><col style="WIDTH: 64px"><col style="WIDTH: 64px"><col style="WIDTH: 64px"><col style="WIDTH: 64px"><col style="WIDTH: 64px"><col style="WIDTH: 64px"><col style="WIDTH: 64px"><col style="WIDTH: 64px"><col style="WIDTH: 64px"></colgroup><tbody>
[TD="bgcolor: #cacaca, align: center"]1[/TD]

[TD="bgcolor: #cacaca, align: center"]2[/TD]

[TD="bgcolor: #cacaca, align: center"]3[/TD]

[TD="bgcolor: #cacaca, align: center"]4[/TD]

[TD="align: right"]25-07-17[/TD]
[TD="align: right"]10:30[/TD]

[TD="align: right"]25-07-17[/TD]
[TD="align: right"]18:15[/TD]

[TD="align: right"]7:45[/TD]

[TD="bgcolor: #99ccff, align: right"]30[/TD]

[TD="bgcolor: #cacaca, align: center"]5[/TD]

[TD="bgcolor: #ffff00"] [/TD]

[TD="bgcolor: #ffff00"] [/TD]

[TD="bgcolor: #99ccff"] [/TD]

[TD="bgcolor: #cacaca, align: center"]6[/TD]

[TD="bgcolor: #99ccff"] [/TD]

[TD="bgcolor: #cacaca, align: center"]7[/TD]

[TD="bgcolor: #99ccff"] [/TD]

[TD="bgcolor: #cacaca, align: center"]8[/TD]

[TD="bgcolor: #99ccff"] [/TD]

[TD="bgcolor: #cacaca, align: center"]9[/TD]

[TD="bgcolor: #99ccff"] [/TD]

[TD="bgcolor: #cacaca, align: center"]10[/TD]

[TD="bgcolor: #99ccff"] [/TD]

[TD="bgcolor: #cacaca, align: center"]11[/TD]

[TD="bgcolor: #99ccff"] [/TD]

</tbody>

Spreadsheet Formulas
CellFormula
B4=TODAY()
F4=TODAY()
I4=+G4-C4

<tbody>
</tbody>

<tbody>
</tbody>

In Row 4 Today's data will be entered. Tomorrow or any day after today when the workbook will be opened Row 4 will become locked automatically. only admin will be able to unlock that.

At the same time B5 & F5 (yellow highlighted) will show the date, on the day the workbook will be opened but if I open today again or the same day it will not show. Then someone will enter the data on that day. when the day will over, again the Row 5 will be locked automatically, that means after 26th or any day the row 4 & 5 will be locked, rest will remain as unlocked.

pls help me to provide a solution.

Regards
RAMU
 
Ah, solved.
Open the Workbook.
Press ALT+ F11.
Doubleclick “ThisWorkBook” in the left side panel
Copy the code and paste it into the large white editor space and then save the workbook.
Code:
Private Sub Workbook_Open()

ActiveSheet.Unprotect
 lastrow = Cells(Rows.Count, "B").End(xlUp).Row
    
    'Selection.FormulaHidden = False
    If Range("B" & lastrow).Value <> Range("A1").Value Then
    Rows(lastrow & ":" & lastrow).Select
    Selection.Locked = True
    Range("B" & lastrow + 1).Formula = "=Today()"
    Range("F" & lastrow + 1).Formula = "=Today()"
    Range("B" & lastrow + 1).Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("F" & lastrow + 1).Select
    Application.CutCopyMode = False
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        Application.CutCopyMode = False
        Range("H" & lastrow + 1).Select
    ActiveCell.FormulaR1C1 = "=RC[-1]-RC[-5]"
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
    End If



End Sub


If you are using the copy from Dropbox then simply saving should be enough otherwise it must be saved as macro enabled, ie, with an “xlsm” extension.

NOTE somewhere I deleted the Formula for Col H by mistake, it is now back.
 
Upvote 0

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Fine tuning:
Delete
"ActiveSheet.Unprotect" and

"Selection.Locked = True" from the macro otherwise cells that are supposed to have been locked are actually unlocked!"
 
Last edited:
Upvote 0
Can you pls allow me to share my original file ? I am little confused, that's why requesting.
The macro works as required except .... it does NOT autorun when the file is opened; that has been my concern from the start.
I presume that you are aware that you can add a password using the Review>Protect option.

It may be necessary to attach the macro to a button but that would still leave "yesterday's" data vulnerable until the macro is run.
 
Upvote 0
By all means, I have been working as best I could from what you were describing.
Now, if that file is reasonably sensitive I will accept a PM.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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