Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Jan 2013
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Update Date When WORKSHEET is CHANGED

    Is there a formula/other that will automatically update the date when the worksheet is changed (not workbook as the workbook has several independent people updating different worksheets)?

    Note: This is a shared document that is updated by multiple people (independent worksheets).

    Thanks!

    Mitch

  2. #2
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Levin, Manawatu-Wanganui, New Zealand
    Posts
    324
    Thanks
    9
    Thanked 28 Times in 26 Posts

    Worksheet_Change event

    Hi
    You could monitor the sheet with the Worksheet_Change event.

    You will need to plan carefully!
    Please do no play with this in a production work book.
    Please do seek additional advice in another forum about this Worksheet_Change event.

    If you find that you start a macro running in an endless loop press Ctrl + Break to interrupt the code.

    An overly simplistic code sample follows below. This is placed in sheetx object with the vba editor.
    The worksheet has a date in cell C1 formatted to display seconds.

    =Now() formatted as d/mm/yyyy h:mm:ss

    Any changes in the range A1:A5 recalculates C1

    Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("A1:A5")) Is Nothing Then
    Range("c1").Calculate
    End If
    End Sub
    Visit this link or this link for further info.

    BTW: Did you intend to post in this Word Processing forum?

    G
    Last edited by geofrichardson; 2015-07-17 at 16:10.

  3. #3
    Gold Lounger Maudibe's Avatar
    Join Date
    Aug 2010
    Location
    Pa, USA
    Posts
    2,635
    Thanks
    115
    Thanked 650 Times in 592 Posts
    Good point Geof regarding the endless loop. As you are probably aware, It can be prevented by using Application.EnableEvents.

    Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
    If Not Intersect(Target, Range("A1:A5")) Is Nothing Then
    Range("c1").Calculate
    End If
    Application.EnableEvents = True
    End Sub
    Mitch,
    To answer your specific question, the following code will update the date in cell A1 if the worksheet is changed:

    In the worksheet module:
    Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
        [a1] = Date
    Application.EnableEvents = True
    End Sub
    HTH,
    Maud
    Last edited by Maudibe; 2015-07-21 at 16:20.

Posting Permissions

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