Forum Discussion
Date of Last Modified for a Cell
That requires VBA code (for Windows and Mac, it won't work in Excel Online, nor on Android or iPhone/iPad).
See the attachment to my reply 5 replies above this one.
I tried the lock cell + protect sheet, but VBA goes on error because it cannot update them too.
- HansVogelaarNov 15, 2023MVP
The code discussed earlier in this topic has a line
rng.Offset(0, 9).Value = Now
Insert a new line below that:
rng.Offset(0, 10).Value = Environ("Username")
- SkydadoNov 15, 2023Copper Contributor
HansVogelaar I promise, last question:
In a shared excel file, is there a way to put the name of the "updater" in the column next to the date+time update column?
- SkydadoNov 14, 2023Copper Contributor
SUPER HansVogelaar !!!!
Thank you very much!!
- HansVogelaarNov 14, 2023MVP
1) In the Visual Basic Editor, select Tools > VBAProject Prpoerties...
Activate the Protection tab.
Tick the check box 'Lock project for viewing'.
Enter a password, and enter it again in the 'Confirm password' box. You will need this if you want to view/edit the code later on, so do not forget it!
Switch back to Excel and save the workbook. The next time someone opens the workbook, they won't be able to view the code unless they enter the correct password.
2) Change
Me.Protect Password:="secret"
to
Me.Protect Password:="secret", AllowSorting:=True
See Worksheet.Protect method for more options.
P.S. If you want to be able to edit cells without triggering the code:
- Activate the Visual Basic Editor.
- Activate the Immediate window (Ctrl+G).
- Type or copy/paste the following line, then press Enter:
Application.EnableEvents = False
- Switch back to Excel.
- When you're done, don't forget to execute
Application.EnableEvents = True
- SkydadoNov 14, 2023Copper Contributor
HansVogelaar Thanks done.
Behaviour is a little bit weird ...
(when unprotected for maintenance, it goes protected if I do something in the "monitored" range.
... but I can live with it.
But I still have 2 issues:
- anyone can "View Code" and see the password.
- the re-protection put standard protection rules but I want to allow, for example, sorting even when protected
Is there a way to protect code view/changes?
- HansVogelaarNov 13, 2023MVP
Unprotect the sheet at the beginning of the code and protect it again at the end:
Private Sub Worksheet_Change(ByVal Target As Range) Me.Unprotect Password:="secret" ' your code ' ... Me.Protect Password:="secret" End Sub
If you protected the worksheet with a password, change secret to your password.
Otherwise, remove both instances of Password:="secret"