is there any excel formula to record cell last change date?

强颜欢笑 提交于 2021-02-11 06:55:26

问题


I'm looking for a way to save the last change date of a cell in Excel without using the Worksheet_Change event. for example define a formula like this:

=LastChangeDate(A22) 

and when the cell A22 changed , current date show in target cell


回答1:


I make a User Defined Function to do that but its is not completely tested. Note two points before using this function :
1- this function shows result after you save document (ctrl+s) or change another cells
2-only change address of target cell and never change other parameters in this function
in fact we record last value of target cell in parameter of function
follow these steps :
1-open MSExcel and make new ".xlsm" file
2-press Alt+F11 to open VBA window
3-Make New Module
4-Copy this code to Module1 :

Public Function LogDate(CellAddress As String, OldValue As String, DisplayDate As String) As String

     Dim CellValue As String
     CellValue = Range(CellAddress).Value
     If CellValue = OldValue Then
        LogDate = DisplayDate
     Else
        Dim Address As String
        Address = Replace(CellAddress, "$", "")

        DisplayDate = Now
        Evaluate "ChangeFormula(""" + Application.Caller.Address(False, False) + """ , """ + Address + """ , """ + CellValue + """ , """ + DisplayDate + """)"
        
        LogDate = DisplayDate
     End If
End Function
 
Private Sub ChangeFormula(CurrentCellAddress As String, Address As String, CellValue As String, DisplayDate As String)
  Range(CurrentCellAddress).Formula = "=LogDate(CELL(""address""," & Address & "),""" & CellValue & """,""" & DisplayDate & """)"
End Sub

4-click on a cell "A2" and write this formula inside it :

=LogDate(CELL("address",A1),"","")

target cell address is "A1" dont change any parameter except "A1"
now when you change "A1" cell value , and save document(ctrl+s) or change other cells , "A2" Display date and time of "A1" changes .



来源:https://stackoverflow.com/questions/65447034/is-there-any-excel-formula-to-record-cell-last-change-date

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!