SOLVED
Home

Formula that's automatic adding date when specific workbook is modified

%3CLINGO-SUB%20id%3D%22lingo-sub-180388%22%20slang%3D%22en-US%22%3EFormula%20that's%20automatic%20adding%20date%20when%20specific%20workbook%20is%20modified%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-180388%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%26nbsp%3B%3C%2FP%3E%3CP%3EI%20want%20as%20a%20part%20of%20my%20headers%20as%20showed%20in%20the%20attached%20example%20file%2C%20a%20cell%20to%20show%20the%20latest%20date%20when%20someone%20has%20made%20any%20modifications%20inside%20the%20workbook.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20there%20any%20formula%20that%20can%20do%20this%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBR%3C%2FP%3E%3CP%3ENiclas%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-180388%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EFormula%20that's%20automatic%20adding%20date%20when%20specific%20workbook%20is%20modified%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-217990%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20that's%20automatic%20adding%20date%20when%20specific%20workbook%20is%20modified%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-217990%22%20slang%3D%22en-US%22%3E%3CP%3EWorks%20perfectly..%20thank%20you.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-217976%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20that's%20automatic%20adding%20date%20when%20specific%20workbook%20is%20modified%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-217976%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F167408%22%20target%3D%22_blank%22%3E%40bob%20....%3C%2FA%3E%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPlease%20try%20this%20code%20instead%3A%3C%2FP%3E%3CPRE%3EPrivate%20Sub%20Workbook_BeforeSave(ByVal%20SaveAsUI%20As%20Boolean%2C%20Cancel%20As%20Boolean)%3CBR%20%2F%3E%20%20%20%20Sheets(%22Sheet1%22).Range(%22B17%22)%20%3D%20Now()%3CBR%20%2F%3EEnd%20Sub%3C%2FPRE%3E%3CP%3EBut%20don't%20forget%20to%20change%20the%20sheet%20name%20(Sheet1)%20into%20the%20real%20name%20of%20your%20existing%20worksheet.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-217933%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20that's%20automatic%20adding%20date%20when%20specific%20workbook%20is%20modified%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-217933%22%20slang%3D%22en-US%22%3E%3CP%3EHaythem%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERunning%20this%20code%20in%20my%20workbook%20produces%20the%20error%20%22Run-time%20error%20'424'%3A%20object%20required%22.%3C%2FP%3E%3CP%3EI%20have%20the%20vba%20code%20in%20ThisWorkbook%20module%20and%20have%20changed%20the%20cell%20as%20follows%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPrivate%20Sub%20Workbook_BeforeSave(ByVal%20SaveAsUI%20As%20Boolean%2C%20Cancel%20As%20Boolean)%3CBR%20%2F%3ETarget.Range(%22B17%22)%20%3D%20Now()%3CBR%20%2F%3EEnd%20Sub%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHow%20can%20I%20get%20around%20this%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-216262%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20that's%20automatic%20adding%20date%20when%20specific%20workbook%20is%20modified%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-216262%22%20slang%3D%22en-US%22%3EThanks%20for%20the%20help.%20I%20will%20give%20it%20a%20go%20and%20let%20you%20know%20if%20it%20works.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-210951%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20that's%20automatic%20adding%20date%20when%20specific%20workbook%20is%20modified%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-210951%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F160272%22%20target%3D%22_blank%22%3E%40Linda%20Burnside%3C%2FA%3E%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20mean%20by%20string%20the%20code%20I%20mentioned%20before%2C%20this%20is%20a%20VBA%20code%2C%20and%20you%20need%20to%20save%20it%20in%20%3CSPAN%3E%3CSPAN%20class%3D%22short_text%22%3E%3CSTRONG%3EThisWorkbook%3C%2FSTRONG%3E%20code%20module.%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22short_text%22%3EPlease%20follow%20this%20%3CA%20href%3D%22http%3A%2F%2Fwww.contextures.com%2Fxlvba01.html%23Workbook%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Elink%3C%2FA%3E%20to%20learn%20how%20to%20install%20this%20code%20into%20your%20own%20workbook.%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22short_text%22%3EAfter%20you%20install%20it%2C%20don't%20forget%20to%20save%20your%20workbook%20as%20%3CSTRONG%3E.xlsm%3C%2FSTRONG%3E%20extension%20because%20the%20regular%20extension%20.xlsx%20doesn't%20allow%20storing%20VBA%20codes.%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22short_text%22%3ERegards%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-210163%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20that's%20automatic%20adding%20date%20when%20specific%20workbook%20is%20modified%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-210163%22%20slang%3D%22en-US%22%3EI%20have%20tried%20copying%20the%20string%20to%20my%20workbook%20but%20it%20doesn't%20work.%20Do%20I%20need%20a%20formula%20in%20the%20destination%20cell%20as%20well%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-210160%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20that's%20automatic%20adding%20date%20when%20specific%20workbook%20is%20modified%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-210160%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Haytham%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20is%20the%20exact%20answer%20to%20my%20query.%20What%20would%20help%20further%20is%20if%20you%20could%20advise%20how%20and%20where%20to%20add%20the%20string%20to%20create%20the%20desired%20result.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3CP%3ELinda%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-180505%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20that's%20automatic%20adding%20date%20when%20specific%20workbook%20is%20modified%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-180505%22%20slang%3D%22en-US%22%3EHi%20Niclas%2C%3CBR%20%2F%3E%3CBR%20%2F%3EIt%20is%20about%20experience.%3CBR%20%2F%3EExperts%20are%20able%20to%20find%20solutions%20at%20a%20fantastic%20speed!%3CBR%20%2F%3EBut%20in%20fact%20they%20have%20spent%20a%20lot%20of%20time%20and%20effort%20to%20reach%20this%20level.%3CBR%20%2F%3EYou%20can%20become%20like%20them!%3CBR%20%2F%3E%3CBR%20%2F%3ERegards%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-180484%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20that's%20automatic%20adding%20date%20when%20specific%20workbook%20is%20modified%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-180484%22%20slang%3D%22en-US%22%3EHi%2C%3CBR%20%2F%3EThanks%20a%20lot%20for%20the%20help%20with%20this%20issue.%3CBR%20%2F%3EThe%20solution%20you%20provided%20works%20perfectly%20fine.%3CBR%20%2F%3EI%60m%20always%20fascinated%20with%20how%20knowledgeable%20people%20are%20able%20to%20find%20solutions%20so%20quick.%20Even%20if%20they%20don%60t%20know%20how%20to%20do%20it%20from%20the%20beginning.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20guess%20thats%20the%20main%20difference%20between%20a%20beginner%20and%20more%20advanced%20users.%3CBR%20%2F%3E%3CBR%20%2F%3EThats%20the%20first%20time%20I%20have%20been%20seeing%20VBA%20within%20excel...%20interesting%3CBR%20%2F%3E%3CBR%20%2F%3EI%20will%20try%20learning%20as%20I%20progress%20within%20excel.%20For%20sure%20it%60s%20a%20quite%20big%20and%20complex%20application%20with%20tons%20of%20features%20to%20explore.%3CBR%20%2F%3E%3CBR%20%2F%3EThanks%20again.%20I%20Will%20for%20sure%20continue%20to%20ask%20my%20way%20forward%20within%20this%20forum%20when%20I%20get%20stuck.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-180397%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20that's%20automatic%20adding%20date%20when%20specific%20workbook%20is%20modified%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-180397%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Niclas%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%3CSPAN%3E%20question%20seems%20easy%20at%20first%20glance!%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EBut%20it%20really%20cannot%20be%20achieved%20in%20native%20Excel%2C%20it%20needs%20VBA%20power!%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EI've%20updated%20your%20workbook%20with%20a%20fairly%20good%20solution%20achieved%20by%20VBA%20which%20is%20the%20Excel%20scripting%20language.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22short_text%22%3EThe%20solution%20is%20this%20code%3A%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CPRE%3EPrivate%20Sub%20Workbook_BeforeSave(ByVal%20SaveAsUI%20As%20Boolean%2C%20Cancel%20As%20Boolean)%3CBR%20%2F%3E%20Target.Range(%22C4%22)%20%3D%20Now()%3CBR%20%2F%3EEnd%20Sub%3C%2FPRE%3E%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22short_text%22%3EWhich%20is%20saved%20in%20ThisWorkbook%20code%20scope.%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22short_text%22%3EWith%20this%20code%2C%20each%20time%20you%20save%20the%20workbook%20(which%20is%20means%20that%20you've%20made%20changes%20to%20it)%20this%20code%20will%20trigger%20and%20fill%20the%20cell%20C4%20with%20the%20today's%20date%20and%20time.%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22short_text%22%3EPlease%20find%20the%20attached%20file.%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22short_text%22%3EHope%20that%20helps%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Niclas Johansson
Occasional Contributor

Hi, 

I want as a part of my headers as showed in the attached example file, a cell to show the latest date when someone has made any modifications inside the workbook.

 

Is there any formula that can do this?

 

BR

Niclas

10 Replies
Solution

Hi Niclas,

 

This question seems easy at first glance!
But it really cannot be achieved in native Excel, it needs VBA power!

 

I've updated your workbook with a fairly good solution achieved by VBA which is the Excel scripting language.

 

The solution is this code:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Target.Range("C4") = Now()
End Sub

Which is saved in ThisWorkbook code scope.

 

With this code, each time you save the workbook (which is means that you've made changes to it) this code will trigger and fill the cell C4 with the today's date and time.

 

Please find the attached file.

 

Hope that helps

Hi,
Thanks a lot for the help with this issue.
The solution you provided works perfectly fine.
I`m always fascinated with how knowledgeable people are able to find solutions so quick. Even if they don`t know how to do it from the beginning.

I guess thats the main difference between a beginner and more advanced users.

Thats the first time I have been seeing VBA within excel... interesting

I will try learning as I progress within excel. For sure it`s a quite big and complex application with tons of features to explore.

Thanks again. I Will for sure continue to ask my way forward within this forum when I get stuck.
Hi Niclas,

It is about experience.
Experts are able to find solutions at a fantastic speed!
But in fact they have spent a lot of time and effort to reach this level.
You can become like them!

Regards

Hi Haytham

 

This is the exact answer to my query. What would help further is if you could advise how and where to add the string to create the desired result.

 

Thanks

Linda

I have tried copying the string to my workbook but it doesn't work. Do I need a formula in the destination cell as well?

Hi @Linda Burnside,

 

If you mean by string the code I mentioned before, this is a VBA code, and you need to save it in ThisWorkbook code module.

Please follow this link to learn how to install this code into your own workbook.

 

After you install it, don't forget to save your workbook as .xlsm extension because the regular extension .xlsx doesn't allow storing VBA codes.

 

Regards

Thanks for the help. I will give it a go and let you know if it works.

Haythem,

 

Running this code in my workbook produces the error "Run-time error '424': object required".

I have the vba code in ThisWorkbook module and have changed the cell as follows:

 

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Target.Range("B17") = Now()
End Sub

 

How can I get around this?

 

Thanks

Hi @bob ....,

 

Please try this code instead:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Sheets("Sheet1").Range("B17") = Now()
End Sub

But don't forget to change the sheet name (Sheet1) into the real name of your existing worksheet.

 

Regards

Works perfectly.. thank you.