+ Reply to Thread
Results 1 to 16 of 16

Update date in a cell when any changes are made and saved on a worksheet

  1. #1
    Registered User
    Join Date
    08-01-2011
    Location
    Denver, CO
    MS-Off Ver
    Excel 2016
    Posts
    23

    Update date in a cell when any changes are made and saved on a worksheet

    Hi there,
    I'd like to have a date displayed on my worksheet that updates ONLY when the worksheet is saved with changes. If I just open it, look at it and close it without saving I want the date to remain unchanged from the last time the worksheet was modified. Can this be done?

    1. I've tried some VBA but it gives me the current date/time stamp each time I open the workbook i.e. each time the macro runs.
    For example, I used this code I found on another forum but it doesn't give me what I want.

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

    2. Plus, if I want to the date to be displayed in cell A2 - what function would I need to put in there?

    Thanks!

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Update date in a cell when any changes are made and saved on a worksheet

    Remove that macro and replace it with this:

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 06-07-2012 at 11:11 AM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    08-01-2011
    Location
    Denver, CO
    MS-Off Ver
    Excel 2016
    Posts
    23

    Re: Update date in a cell when any changes are made and saved on a worksheet

    Thanks, I'll try this code but what goes into cell A2?

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Update date in a cell when any changes are made and saved on a worksheet

    It looks like that code would put the current date. You could change Date to Now and it would put the entire date/time stamp into that cell, then you could format that cell to display any way you wanted.

  5. #5
    Registered User
    Join Date
    08-01-2011
    Location
    Denver, CO
    MS-Off Ver
    Excel 2016
    Posts
    23

    Re: Update date in a cell when any changes are made and saved on a worksheet

    Unfortunately it's not working for me. Every time I open the file it updates the date to "now". What I'm looking for is if I open the file on 6/7/2012 but the last time it was saved was on 6/1/2012 I want 6/1/2012 to be displayed. Thanks anyway.

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Update date in a cell when any changes are made and saved on a worksheet

    The code I gave you does not change the date to the current date unless you make a physical change to something in the workbook. Perhaps you have other code that does? Do you have a Workbook_Open macro in there somewhere?

  7. #7
    Registered User
    Join Date
    08-01-2011
    Location
    Denver, CO
    MS-Off Ver
    Excel 2016
    Posts
    23

    Re: Update date in a cell when any changes are made and saved on a worksheet

    Hmm, I am missing something then. If you would be kind enough to take a look at my workbook, I would be eternally grateful. I'm missing the connection of how to get it to show up in the cell where I want it (AK1). Thank you!!

    test.xls

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Update date in a cell when any changes are made and saved on a worksheet

    The macro I gave you is to put a timestamp on that sheet if a change is made anywhere on any sheet in the workbook. Workbook level events do not go into Sheet modules, they go into the ThisWorkbook module. Take it out of the sheet module and put it in the ThisWorkbook module.

    If you want a version of that macro that only works on the 1. People Sheet (meaning you can edit the other sheets without causing a timestamp update), you can put this into that sheet module:

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    08-01-2011
    Location
    Denver, CO
    MS-Off Ver
    Excel 2016
    Posts
    23

    Re: Update date in a cell when any changes are made and saved on a worksheet

    I'm sorry to be so thick about this but I used the new code you posted for just changes on the People Sheet tab but no date shows up in cell AK1 when I make and save changes. Do I need to enter anything into cell AK1 to make that code display the date? Thank you again for your help.

  10. #10
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Update date in a cell when any changes are made and saved on a worksheet

    The new code does go in the sheet module. The original code does not.

  11. #11
    Registered User
    Join Date
    08-01-2011
    Location
    Denver, CO
    MS-Off Ver
    Excel 2016
    Posts
    23

    Re: Update date in a cell when any changes are made and saved on a worksheet

    I'm sorry, we're clearly not understanding each other. I've put the code in the sheet module but still no date appears when I make and save changes. Could you just fix it in the sheet I attached above and reattach it.

  12. #12
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Update date in a cell when any changes are made and saved on a worksheet

    No, you post your edited sheet and let me see what you've done.

  13. #13
    Registered User
    Join Date
    08-01-2011
    Location
    Denver, CO
    MS-Off Ver
    Excel 2016
    Posts
    23

    Re: Update date in a cell when any changes are made and saved on a worksheet

    All I've done is paste your code in...I don't know what to do from there.
    Attached Files Attached Files

  14. #14
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Update date in a cell when any changes are made and saved on a worksheet

    Your workbook worked for me immediately.

    Close your Excel completely, reopen and try again. I think you just got stuck with macros disabled temporarily.

  15. #15
    Registered User
    Join Date
    08-01-2011
    Location
    Denver, CO
    MS-Off Ver
    Excel 2016
    Posts
    23

    Re: Update date in a cell when any changes are made and saved on a worksheet

    Yep, that was it. Thanks again for your help.

  16. #16
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Update date in a cell when any changes are made and saved on a worksheet

    If that takes care of your need, please select Thread Tools from menu above and set this topic to SOLVED.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1