Forum Discussion
Date of Last Modified for a Cell
HansVogelaar --thanks for helping all of us!
I read all of the previous replies. I cannot see the Drive file so I am hoping you can help me with my error.
I want column B to autofill with the date when its corresponding cell in column A is edited. Am I going about this incorrectly?
I know I have it populating in C, this was for demo. 🙂
If you want to enter the date in column B when the corresponding cell in column A is filled for the first time, you can use a formula. (Or did you mean column C instead of column A?)
If you want to enter the date in column B whenever the corresponding cell in column A is edited, you'll need VBA code.
Which do you want?
- 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.
- MDCKVMar 06, 2024Copper Contributor
Yes, they are. I am that fancy.
P.S. I decided to make Table2 align with Table1 so I can extend Table1 and just have the one VBA that I know works in there.
- HansVogelaarMar 05, 2024MVP
Are your tables really named Table1 and Table2?
- MDCKVMar 05, 2024Copper Contributor
HansVogelaar Hmm, no dice. Here is the code modified accordingly. Thoughts?
Private Sub Worksheet_Change(ByVal Target As Range) Dim tbl As ListObject Dim rng As Range Set tbl = Me.ListObjects("Table1") Set rng = Intersect(tbl.ListColumns("Balance").DataBodyRange, Target) If Not rng Is Nothing Then Application.ScreenUpdating = False Application.EnableEvents = False rng.Offset(0, 3).Value = Now Application.EnableEvents = True Application.ScreenUpdating = True End If Set tbl = Me.ListObjects("Table2") Set rng = Intersect(tbl.ListColumns("Statement Date").DataBodyRange, Target) If Not rng Is Nothing Then Application.ScreenUpdating = False Application.EnableEvents = False rng.Offset(0, 3).Value = Now Application.EnableEvents = True Application.ScreenUpdating = True End If End Sub
- HansVogelaarMar 03, 2024MVP
See if you can modify this to match your setup:
Private Sub Worksheet_Change(ByVal Target As Range) Dim tbl As ListObject Dim rng As Range Set tbl = Me.ListObjects("Table1") Set rng = Intersect(tbl.ListColumns("Balance").DataBodyRange, Target) If Not rng Is Nothing Then Application.ScreenUpdating = False Application.EnableEvents = False rng.Offset(0, 3).Value = Now Application.EnableEvents = True Application.ScreenUpdating = True End If ' *** Change the table name as needed *** Set tbl = Me.ListObjects("Table2") ' *** Change the column name as needed *** Set rng = Intersect(tbl.ListColumns("ColumnName").DataBodyRange, Target) If Not rng Is Nothing Then Application.ScreenUpdating = False Application.EnableEvents = False ' *** Change the column offset 3 as needed *** rng.Offset(0, 3).Value = Now Application.EnableEvents = True Application.ScreenUpdating = True End If End Sub
- MDCKVMar 03, 2024Copper Contributor
peiyezhu as written, that did not work and I had tried other variations of the same thing with the obvious change of Table1 to Table2. I receive multiple errors with a variety of edits, including the one proposed here. If I put it after "End Sub" it's a problem. If I remove "End If" and "End Sub" and insert it right after the end of the last set of instructions I get "Block If without End If."
- peiyezhuMar 03, 2024Bronze ContributorAdd below block,I guess
Set tbl = Me.ListObjects("Table2")
Set rng = Intersect(tbl.ListColumns("Balance").DataBodyRange, Target)
If Not rng Is Nothing Then
Application.ScreenUpdating = False
Application.EnableEvents = False
rng.Offset(0, 3).Value = Now
Application.EnableEvents = True - MDCKVMar 02, 2024Copper Contributor
HansVogelaar Thank you very much for the time you took to reply to this thread in such detail. After reading the entire thread, I was able to create the VBA I needed to make my situation work. I need to figure out how to have this same function for two tables on the same worksheet. You have contributed so much, so I'm not asking you to give me the answer but if it's no trouble, would you mind letting me know how to apply this to a second table in the same worksheet? Here is what I used:
Private Sub Worksheet_Change(ByVal Target As Range) Dim tbl As ListObject Dim rng As Range Set tbl = Me.ListObjects("Table1") Set rng = Intersect(tbl.ListColumns("Balance").DataBodyRange, Target) If Not rng Is Nothing Then Application.ScreenUpdating = False Application.EnableEvents = False rng.Offset(0, 3).Value = Now Application.EnableEvents = True Application.ScreenUpdating = True End If End Sub
- HansVogelaarFeb 11, 2024MVP
As far as I know, this is not possible in Excel Online, sorry.
- Aldossary1017Feb 11, 2024Copper Contributor
HansVogelaar Dear Hans thank you so much for the amazing explaining. I went through every step and it all went perfect. Moreover, will you be able to assist me or is there a solution for an online worksheet in excel 365 ? because I couldn't save the changes and I am working with a team on that excel worksheet please your support is appreciated
- HansVogelaarNov 29, 2023MVP
Like this:
Private Sub Worksheet_Change(ByVal Target As Range) Dim rng As Range Dim cel As Range Set rng = Intersect(Range("K12:K" & Rows.Count), Target) If Not rng Is Nothing Then Application.ScreenUpdating = False Application.EnableEvents = False rng.Offset(0, 2).Value = Date rng.Offset(0, 4).Value = Environ("Username") For Each cel In rng Select Case cel.Value Case Range("S5").Value, Range("S6").Value cel.Offset(0, 1).Value = Date End Select Next cel Application.EnableEvents = True Application.ScreenUpdating = True End If End Sub
- RCFUNNov 29, 2023Copper Contributor
This is awesome,
I came up with the below.
Basically if K get changed at all it updates M with the Date and P with the username.
K Value is a drop down menu of cells in S2-S7.
What i also need is L to update the date if and only if K= S5 or S6
Is that something that can be esily added?
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Range("K12:K" & Rows.Count), Target) Is Nothing Then
Application.ScreenUpdating = False
Application.EnableEvents = False
Intersect(Range("K12:K" & Rows.Count), Target).Offset(0, 2).Value = Date
Intersect(Range("K12:K" & Rows.Count), Target).Offset(0, 4).Value = Environ("Username")
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End Sub - HansVogelaarNov 22, 2023MVP
That is an unavoidable consequence of running VBA code...
- ahawkins91Nov 22, 2023Copper Contributor
HansVogelaar that worked!! Thank you so much!
I noticed that the undo function is no longer available. Do you know why? And a fix for that? - HansVogelaarNov 21, 2023MVP
Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Range("C2:C" & Rows.Count), Target) Is Nothing Then Application.ScreenUpdating = False Application.EnableEvents = False Intersect(Range("C2:C" & Rows.Count), Target).Offset(0, 4).Value = Date Application.EnableEvents = True Application.ScreenUpdating = True End If End Sub
- ahawkins91Nov 21, 2023Copper Contributor
HansVogelaar Hi Hans! I’m trying to essentially do the same thing as the OP. I copied and pasted the VBA you provided, but it doesn’t seem to be working for me. Do you think that you could provide another VBA code for me please? I would like the date in column G to update whenever column C is modified. I would like G2 to update when C2 is modified. G3 to update when C3 is modified, G4 to update when C4 is modified…so on and so fourth. Thank you in advance!
- 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.