Want to lock range of cells after time stamp entered.

surajit_raj

New Member
Joined
Feb 16, 2019
Messages
2
Hi,
Please help me to write a code for the below mentioned scenario.

I want to put a time stamp using =now command in VB in a range of cells (example B2:C25) and cells will be locked once the data is entered with a password and apart from B2:C25 all the cells are editable and unlocked.

Need an urgent help. Please help.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Locking a range of cell is actually changing the cells properties to protected vs unprotected and then locking the entire sheet. select and right click on cells in a range goto properties and protect.

then look for VBA to toggle on/off sheet protect with password
 
Upvote 0
Will all the cells in the range have a time stamp or only some of the cells? Do you want each cell locked as you enter the time stamp in each one?
 
Last edited:
Upvote 0
Begin by unlocking all the cells in the sheet. Then protect the sheet with a password of your choice. The macro assigned to the buttons should look something like this. Change myPasswordHere (in red) to your password. Change the range (in blue) accordingly.
Code:
Sub InsertTimeStamp()
    ActiveSheet.Unprotect Password:="[COLOR="#FF0000"]myPasswordHere[/COLOR]"
    Range("[COLOR="#0000FF"]C20[/COLOR]") = Now()
    ActiveSheet.Protect Password:="[COLOR="#FF0000"]myPasswordHere[/COLOR]"
End Sub
Copy and paste this macro into the worksheet code module. Do the following: right click the tab name for your sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("B2:C25")) Is Nothing Then Exit Sub
    Target.Locked = True
End Sub
Click a button to enter the time stamp.
 
Upvote 0

Forum statistics

Threads
1,223,703
Messages
6,173,983
Members
452,540
Latest member
haasro02

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