Could some one help me with a VBA code for showing Date and User name stamp when any change has been made to (Column A) of my table?
The VBA code I have works when typing in directly the new status in my table, but when Refreshing Data from a Query (Different Table), then new Columns get added
to the table and mess up with headers as well. I need to see all the stamps by just refreshing the Data:
Private Sub Worksheet_Change(ByVal Tgt As Range)
Dim MyData As Range
Dim MyDataRng As Range
Set MyDataRng = ActiveSheet.ListObjects("My Table").ListColumns(3).DataBodyRange
If Intersect(Tgt, MyDataRng) Is Nothing Then Exit Sub
On Error Resume Next
If Tgt.Offset(0, 1) = "" Then
Tgt.Offset(0, 1) = Now
Else
Tgt.Offset(0, 2) = Now
Tgt.Offset(0, 3) = Aplication.UserName
End If
For Each MyData In MyDataRng
If MyData = "" Then
MyData.Offset(0, 1).ClearContents
End If
Next MyData
End Sub
The VBA code I have works when typing in directly the new status in my table, but when Refreshing Data from a Query (Different Table), then new Columns get added
to the table and mess up with headers as well. I need to see all the stamps by just refreshing the Data:
Private Sub Worksheet_Change(ByVal Tgt As Range)
Dim MyData As Range
Dim MyDataRng As Range
Set MyDataRng = ActiveSheet.ListObjects("My Table").ListColumns(3).DataBodyRange
If Intersect(Tgt, MyDataRng) Is Nothing Then Exit Sub
On Error Resume Next
If Tgt.Offset(0, 1) = "" Then
Tgt.Offset(0, 1) = Now
Else
Tgt.Offset(0, 2) = Now
Tgt.Offset(0, 3) = Aplication.UserName
End If
For Each MyData In MyDataRng
If MyData = "" Then
MyData.Offset(0, 1).ClearContents
End If
Next MyData
End Sub