Forum Discussion
Date of Last Modified for a Cell
After reopening the workbook, and if asked, allowing macros, change the value of a cell in column A from A2 down. The date should appear in the corresponding cell of column B.
- JahtibaCSep 25, 2024Copper Contributor
washcaps2 I HansVogelaar I got up to this point following along but I am getting the 12:00 AM error. What was the solution to give the actual time? Thank you.
- HansVogelaarNov 08, 2023MVP
Make the folder containing the workbook a Trusted Location for Excel.
File > Options > Trust Center > Trust Center Settings... > Trusted Locations.
- FaytaxNov 08, 2023Copper ContributorHans, I have an issue with this sheet and with other macros sheets as well. When I create the sheet its all fine but when I want to open it again, Microsoft automatically blocks the macros from running. Is there anything I can do about it. It happens even if its a macro enabled worksheet and I have enabled the macros by properties of the sheet.
I really appreciate your assistance! - FaytaxNov 08, 2023Copper ContributorThanks so much Hans!
- HansVogelaarNov 07, 2023MVP
See the attached version. To view/edit the code, right-click the sheet tab and select View Code from the context menu.
- FaytaxNov 07, 2023Copper Contributorok, got it. I do want column J to be updated every time I update Column A. I tried to do a VBA code but it didn't work. I have no previous experience in VBA.
Thanks so much for your assistance! - HansVogelaarNov 02, 2023MVP
Thanks!
You got the formula the wrong way round, assuming that you want a timestamp in column D when the user enters a value in column D.
It will only work if column D is still empty when you create the formulas in column J. The formula in J5 should be
=IF(D5<>"",IF(J5<>"",J5,NOW()),"")
And remember that you have to enable iterative calculation in File > Options > Formulas.
If you want column J to be updated each time you edit column D, you need VBA code, not a formula.
- FaytaxNov 02, 2023Copper Contributor
See attached the sheet.
Another issue is that if one cell updates with the date then all cells update.
https://1drv.ms/x/s!Avzs3jKduffg1hpOPBFgykz9_O0n?e=7a4cPA
Thanks so much for your assistance
- HansVogelaarNov 01, 2023MVP
In the formula in my first reply, A2 is the cell you want to track and A3 is the cell with the tine stamp.
If you cannot get it to work: could you attach a small sample workbook demonstrating the problem (without sensitive data), or if that is not possible, make it available through OneDrive, Google Drive, Dropbox or similar?
- FaytaxNov 01, 2023Copper ContributorHi Hans,
I have read your initial answer and all replies through. When I put the formula into my sheet it works but when I update the cell that I want tracked, the date updated changes to the word in the tracked cell. Can you advise what I can do about that. I want date and times only. - washcaps2Oct 06, 2023Copper ContributorYeah I think the problem was when I inserted a column. It then put the last edit time in all rows to the end. Should be good now. Thanks again!
- HansVogelaarOct 06, 2023MVP
Did you perhaps do something that caused the code to enter the date and time in ALL rows of column K? If so, do the following:
- Activate the Visual Basic Editor.
- Press Ctrl+G to activate the Immediate window.
- Type (or copy/paste) the line Application.EnableEvents = False
- With the insertion point in that line, press Enter.
- Switch back to Excel.
- Select all rows from the row below the "real" used range of the sheet to the very last row 1048576.
- Right-click in the selection and select Delete.
- Activate the Visual Basic Editor.
- Press Ctrl+G to activate the Immediate window.
- Type (or copy/paste) the line Application.EnableEvents = True
- With the insertion point in that line, press Enter.
- Switch back to Excel.
- Save the workbook.
- washcaps2Oct 06, 2023Copper Contributor
- washcaps2Oct 06, 2023Copper Contributor
HansVogelaar Did this screenshot work? It's the error message I get
- HansVogelaarOct 06, 2023MVP
That must have another cause. The code doesn't impose a limit.
- washcaps2Oct 06, 2023Copper Contributor
Thanks, that worked. Only problem I'm having is that I can't insert rows as it says the limit is exceeded. I'll only ever need 200 rows or so. Can I limit it to 200 rows instead of the million?
- HansVogelaarSep 29, 2023MVP
Let's say you want the timestamp in column M.
Use this variation of the code posted higher up:
Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Range("C2:C" & Rows.Count & ",E2:F" & Rows.Count & _ ",J2:K" & Rows.Count), Target) Is Nothing Then Application.ScreenUpdating = False Application.EnableEvents = False Intersect(Range("M:M"), Intersect(Range("C2:C" & Rows.Count & _ ",E2:F" & Rows.Count & ",J2:K" & Rows.Count), Target).EntireRow).Value = Now Application.EnableEvents = True Application.ScreenUpdating = True End If End Sub - washcaps2Sep 29, 2023Copper Contributorfigured out the time part
- washcaps2Sep 29, 2023Copper ContributorMy date is working but the time is coming up at 12:00 AM
Also, how can I set it up to update the date and time of last edit if something in columns G through J were edited? Or in columns C, E, F, J, K?