Forum Discussion
Automatically adding the date/time to a cell when another cell is updated
Haytham - Thank you so much for the quick response on this. This works perfectly and I can see that changing the target offset allows me to change the location of the timestamp.
This is great and exactly what I needed. I really appreciate the help.
Thank you, but I have discovered a simplified version of the code as follows:
Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1,B1,C1,D1,E1")) Is Nothing Then
Target.Offset(1, 0) = Now
End If
End Sub
It works the same as the previous one, so I recommend you to use it instead.
Regards
- EliasDFeb 07, 2025Copper Contributor
Hello Haytham, I know this thread is quite old. And I got this code to work perfectly in my MacBook excel. However, when I increase the Range from ("B2:B10000, through, BK2:BK10000") then for some reason it stops working. Even when reducing it back down to only be 99 lines per column it breaks. Any idea why?
- MedinaJ78Jan 18, 2022Copper Contributor
Haytham Amairah
Any other good sources using VBA, this thread looks like it ended up saying the opposite of you and died. But this is exactly what I need. I could use some help on what to search for to help find what I need.
Thanks.- kovespJan 19, 2022Copper Contributor
=IF(ISBLANK(C1)," ",IF(ISBLANK(B1)," ",NOW()))
The current date is to be automatically inserted into B1 when C1 becomes non-blank.
For this to work, one needs to set Enable iterative calculation on the Formulas page of Options.
However ...
- This used to work in the Android version of Excel when using the smae workbook, but Microsoft, in their wisdom, "fixed"it at some point and there is no option for enabling iterative calculation in the Android version.
- Worse, when the workbook is then opened in Windows, the option is turned off, hence the formula stops working.
- The option remains set, as long as the workbook is not touched on Android.
When I added this macro to the workbook
Private Sub Workbook_Open()Application.Iteration = TrueEnd Suband saved it as XLSM (as required) it started working again. It now also works on Android, despite showing a message that the Android version doesn't support VBA.
Ah, the mysterious ways of Microsoft ...
Anyway ... thanks for asking the question: I didn't think of trying the above before now.
- Sloany2385May 07, 2022Copper ContributorNot sure if anyone can help me out with this , but im sure this will need to be input through VBA , im looking to make 1 cell update the date ONLY every 7th day for example , i have a spread sheet that i have to input personnel info as the come to and leave our facility , and at the top of this spread sheet are a series of cells that read **IN THIS ORDER** "Arrivals (Wed-Tues)" "5/4/22" "THROUGH" "5/10/22" so where "5/4/22" is i am looking to have this particular cell update ESSENTIALLY every wed , IE i need 5/4/22 to update to 5/11/22 , i already have the formula figured out for the 5/10/22 part that is easy such and such +6 and you have the 7th day of your week , i have searched high and low for an existing VBA code to create this but have had no luck thus far , can anyone help me?
- Jin_TangJul 06, 2021Copper ContributorHi, I tried using this code, and the first code mentioned. However, it doesn't seem to be working for me. regardless of what i enter in A1/B1/C1/D1/E1, there seems to be no output in A2/B2/C2/D2/E2.
Is there any settings that i should enable before writing this vba?- kovespSep 04, 2021Copper Contributor
No VBA needed; and that would not work when the workbook is opened in the browser or mobile platforms.
If the column where you want to automatically set the current date is say B, the column where the data is being entered is say C, and you are starting from B1 then therre are two variants:
- If you want the date to update whenever the data is changed in column C, then place
=IF(ISBLANK(C1)," ",NOW())
in B1 and copy down. - If you want the date to be set only when the data in column C is changed from blank to a non-blank value (but not when the value is changed from non-black value to another non-blank value) then place
=IF(ISBLANK(C1)," ",IF(ISBLANK(B1)," ",NOW()))
in B1 and copy down.
These work when the workbook is opened from Windows or Android (so it probably also works on IOS, but I don't use that platform, so can't verify).
Note: There was a previous reply which was similar to the first option above, but used TODAY(). That won't work, because the TODAY() function updates whenever the workbook is opened. NOW() will not do that, it "freezes" the date when invoked.
- If you want the date to update whenever the data is changed in column C, then place
- wlademiramaralApr 15, 2021Copper Contributor
hi
can you please tell me how can i change from lines to collum? i'm trying to do the same thing but instead of changing specific rows, i'd like to everytime i change a collum cell it brings the now date on the right cell 😞
- Joseph HuismanOct 02, 2018Copper Contributor
Thanks for the simplified version. One more question for you, I tried replacing "Now" with "Today" to get just the date but that didn't work. How can I change this so it only shows the date if needed?
- Haytham AmairahOct 02, 2018Silver Contributor
Hi Joseph,
There is no function in VBA called Today, the VBA function equivalent to the Worksheet function https://support.office.com/en-us/article/TODAY-function-5EB3078D-A82C-4736-8930-2F51A028FDD9 is https://docs.microsoft.com/en-us/office/vba/Language/Reference/User-Interface-Help/date-function.
So you have to use Date instead of Today as follows:
Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1,B1,C1,D1,E1")) Is Nothing Then
Target.Offset(1, 0) = Date
End If
End SubAfter you apply this change, you may get the date in the worksheet like this:
Where time appears as zeros!
If you encounter it, don't worry, it's just a format, and you can change it to a short date from the Home tab as follow:
Hope that helps
- Joseph HuismanOct 03, 2018Copper Contributor
Thanks again. You have been a huge help here. So I have one more question on this. The macro works when I manually update the cell, the date plugs in just perfect and it updates every time I update the cell. However, I was hoping that this would also work if the cell was updated by input into another cell.
For example, if A1 has data and A2 is where the date updates automatically, I want to have a formula in A1 that says "=Sheet2:A1". I then enter data into Sheet2:A1 and that data also updates in A1 on the original sheet but the date does not update in this case.
What I am ultimately trying to do is create a sheet that updates the date when certain fields are updated but I want those fields to be updated by inputs from another sheet. I hope this makes sense.
Is there a way to do this or does the macro only run if the cell is updated manually on that sheet?
I appreciate any help you can provide.