Forum Discussion
Date of Last Modified for a Cell
HansVogelaar I apologize for treading up an old thread.
but is there a way to make the formula work to update the date and time every time the data cell changes and not just the first time the cell receives data input? Regardless if the data cell had data to begin with?
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.
- HansVogelaarNov 15, 2023MVP
The code discussed earlier in this topic has a line
rng.Offset(0, 9).Value = NowInsert 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:=TrueSee 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 SubIf you protected the worksheet with a password, change secret to your password.
Otherwise, remove both instances of Password:="secret"
- SkydadoNov 13, 2023Copper ContributorWhen using VBA, can you pls suggest how to protect the cells with dates to prevent user modifications?
I tried the lock cell + protect sheet, but VBA goes on error because it cannot update them too. - JustquestionsNov 09, 2023Copper Contributor
HansVogelaar Ah Apologies, I didn't realize there was more than the first page of replies while looking at the forum on my phone.
I will use this information and hopefully learn from it. I have never used VBA code before and didn't know it existed.
Thank you.