问题
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