简体   繁体   中英

last update date of a range stored in the single cell excel

So I have this excel worksheet, where I have a range A2:A3, I would like to know if I can store last time of update of that specific range to a cell lets say in B1? I am really knew in VBA world. Will really appreciate any help :)

  • right click your sheet tab
  • View Code
  • copy and paste in the code below
  • back to Excel

code

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng1 As Range
Set rng1 = Intersect([a2:a3], Target)
If rng1 Is Nothing Then Exit Sub
Application.EnableEvents = False
[b1] = Format(Now(), "dd-mm-yyyy hh:mm:ss")
Application.EnableEvents = True
End Sub

'This Macro has been written to update Last modified date/time on each A2:D43415 'Last Modified date applied to column F.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rInt As Range
Dim rCell As Range
Dim tCell As Range
Dim tColInt As Integer

tColInt = 6 'Column Index, Example: A=1, B=2, ...... ,Z=26


Set rInt = Intersect(Target, Range("A2:D43415")) 'Change cell range
 If Not rInt Is Nothing Then
    For Each rCell In rInt
        Set tCell = Cells(rCell.Cells.Row, tColInt)
        If IsEmpty(tCell) Or Not IsEmpty(tCell) Then
            tCell = Now
            tCell.NumberFormat = "dd/mm/yyyy h:mm:ss AM/PM" 'Custom Format
        End If
    Next
 End If
End Sub

Click to See Output

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM