+ Reply to Thread
Results 1 to 6 of 6

How to display last modified date in EACH worksheet

Hybrid View

  1. #1
    Registered User
    Join Date
    04-12-2013
    Location
    NYC, NY
    MS-Off Ver
    Excel 2010
    Posts
    4

    How to display last modified date in EACH worksheet

    good morning, all - i have searched for over half an hour now on this and finally decided to reach out to the community. the various responses to the posts i found in re to this were not specifically addressing what is currently happening in my test worksheet. hopefully, someone can shed some lite.

    trying to have a cell in each worksheet of a workbook display the last time that specific worksheet was edited. currently, i have the following code on the module level for the three sheets {fyi - each corresponding =SavedDate#() is in cell C1}:

    Function SavedDate() As Date
    Application.Volatile
    SavedDate = ActiveWorkbook.BuiltinDocumentProperties.Item(12)
    End Function

    --

    Function SavedDate1() As Date
    Application.Volatile
    SavedDate1 = ActiveWorkbook.BuiltinDocumentProperties.Item(12)
    End Function

    --

    Function SavedDate2() As Date
    Application.Volatile
    SavedDate2 = ActiveWorkbook.BuiltinDocumentProperties.Item(12)
    End Function
    *******

    the first test using those three fcn statements worked perfectly where the cell "C1" correctly displayed the last edit after saving/reopening the workbook a couple of times. of course, ALL three modified dates were identical {pls note - i have the cells formatted to show the date AND time to test if the macro is actually working, so that has not been an issue thus far as i can plainly see it showing, say, 4/12/13 3:45am or 4/12/13 3:32am and so forth}.

    however, when i went to add the SECOND part of each macro on the sheet level {e.g., using right click/View Code}, here is where the problem occurred. since i specifically want the sheets to be independent of each other, i cannot just use the three macros from above. i thought--based on searching various sites and playing around w/the code--that the following things added at the sheet level would take care of the three dates being independent and only changing in a specific sheet if that sheet was edited. alas, i keep getting these run-time errors ==> Method 'Range' of object'_Worksheet' failed

    i did not think i had to do anything extra to each sheet's code than what i am pasting below {so, did not think any special naming of add'l variables or defining things and so forth would be necessary, correct or...???}:

    Private Sub Worksheet_Change(ByVal Target As Range)
    ActiveSheet.Range("C1") = SavedDate
    End Sub

    --

    Private Sub Worksheet_Change(ByVal Target As Range)
    ActiveSheet.Range("C1") = SavedDate1
    End Sub

    --

    Private Sub Worksheet_Change(ByVal Target As Range)
    ActiveSheet.Range("C1") = SavedDate2
    End Sub
    ********

    and when i debug, of course it just goes to the one line of code "ActiveSheet.Range(..." in each. right now i have this second part in comment mode ['] and still trying to search and play, but i defer to the experts here.

    thx in advance for any assistance. i do hope i provided sufficient information for the dilemma since this is my official first posting. i thought this was going to be a slam dunk but i had to laugh at myself that it has already turned into an hour+ . go figure.

    best-

    MLA

    **********UPDATE********

    if anyone is still awake, i found a slight variation to the sheet level coding. how odd - now i no longer get the run-time error msg, BUT this code ends up making ALL dates/times in EACH worksheet identical, thus defeating the purpose of independent modified date calcs. for each worksheet i will add the code here but i guess i will continue to search until i am too tired to think. <:o) thx again if anyone can assist.

    here is the slight variation in code @ sheet level i just found/edited for my testing:

    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    Sh.Range("C1").Value = SavedDate
    End Sub

    ----

    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    Sh.Range("C1").Value = SavedDate1
    End Sub

    ----

    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    Sh.Range("C1").Value = SavedDate2
    End Sub

    ****

    a final thought - i do not think this should matter but i will name that "C1" range in each separate worksheet just to see if that will make the dates change independently of each other if three different ranged names are used...probably not, i guess. does not hurt to test @ this point, tho.

    okay - thx again, anyone, for your help. best-

    MLA
    Last edited by mimilafl; 04-12-2013 at 04:56 AM. Reason: found add'l coding but still not working correctly

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: How to display last modified date in EACH worksheet

    Code in Thisworkbook object

    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    
        If TypeOf Sh Is Worksheet Then
            Application.EnableEvents = False
            Sh.Range("C1") = ThisWorkbook.BuiltinDocumentProperties(12)
            Application.EnableEvents = True
        End If
        
    End Sub
    C1 will update when a change occurs.
    Attached Files Attached Files
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    04-12-2013
    Location
    NYC, NY
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: How to display last modified date in EACH worksheet

    Andy Pope - thx so much for your reply. i wanted to see if things would work in my test sheets first prior to responding. initially, they were still screwy, so i opened your attchmt {thx 4 that, too} but found it to be very different from my test sheets.

    however, i can still lol even at this time of nite and being really tired now. it took me a nyc minute, but i realized the MAIN diff betw. your three sheets and mine was that you did NOT use any module to calculate the last change date like i was doing. once i commented out those three modules {was simply too chicken to just delete them altogether} it was sheer magic ==> cell C1 in all three worksheets changed at a variety of times so i did not need the "=SavedDate...." formula in them and i had already abandoned not naming the ranges b/c i was really confident with only using the straight "C1."

    the trooper that i am, i will read up on the features of the ThisWorkbook and why it was not necessary to add anything related to actually calculating the dates; hence, no need for those modules. so it looks like the combo of Option Explicit and the change statement was all that was needed. truly amazing.

    oddly, the "Application.EnableEvents =T/F" lines of code were in the updated info i found earlier & posted, but since i prefer clean&short code, i tested commenting them both out and it did not seem to matter...well; meaning i did not get error msgs altho they were still all changing to the same date/time before. but that is the reason why my updated post did not include them. i did keep them in yours based on the different way you set the sheets up from me.

    u r certainly worth your weight in gold and i truly appreciate your assistance. this is such fun stuff .

    have a fantastic wkend-

    MLA

  4. #4
    Registered User
    Join Date
    04-12-2013
    Location
    NYC, NY
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: How to display last modified date in EACH worksheet

    good morning, Andy Pope - wanted to touch base w/you to let you know i altered one thing from your code.

    i let out a shrill today when i opened my test sheet and the date/times were not what i was expecting. they kept showing yesterday's vals in each sheet. i then realized...a well duh moment...i actually do not want/need the last save date[val=12]. i am more interested in the editing of the worksheet. i swapped out that language and replaced w/current date; worked like a charm. have a terrif wkend. w/kindest regards, MLA

    Sh.Range("C1") = Now()

  5. #5
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,058

    Re: How to display last modified date in EACH worksheet

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code in [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    Never use Merged Cells in Excel

  6. #6
    Registered User
    Join Date
    04-12-2013
    Location
    NYC, NY
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: How to display last modified date in EACH worksheet

    okay; thx-

+ 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