legalhustler
Well-known Member
- Joined
- Jun 5, 2014
- Messages
- 1,168
- Office Version
- 365
- Platform
- Windows
Hello VBA Gurus!
I want to keep a track of any changes (doesn't necessarily have to track any formatting changes) to a specific sheet in a separate sheet called "Log". I found the following code that almost does what I want but I would like to break the attributes in different columns instead of one cell. I need the following fields in this specific order:
1) Computer Name - currently it uses the Excel application name, but I need the computer name. I think code is supposed to use the Environ function to do that.
2) Cell - this is the cell that is being changed, should be relative cell reference like B2 and not $B$2
3) Previous Amount - should use "$" sign and comma for each number unit. For negatives it should be use the parenthesis format i.e. "$ (xxx,xxx).
4) Current Amount - See above. If the amount gets deleted then the current amount should show a blank.
5) Date - date of change i.e. 7/26/2021
6) Time - time of change i.e. 12:53 PM (no need to put the seconds)
Any help is appreciated. TIA!
I want to keep a track of any changes (doesn't necessarily have to track any formatting changes) to a specific sheet in a separate sheet called "Log". I found the following code that almost does what I want but I would like to break the attributes in different columns instead of one cell. I need the following fields in this specific order:
1) Computer Name - currently it uses the Excel application name, but I need the computer name. I think code is supposed to use the Environ function to do that.
2) Cell - this is the cell that is being changed, should be relative cell reference like B2 and not $B$2
3) Previous Amount - should use "$" sign and comma for each number unit. For negatives it should be use the parenthesis format i.e. "$ (xxx,xxx).
4) Current Amount - See above. If the amount gets deleted then the current amount should show a blank.
5) Date - date of change i.e. 7/26/2021
6) Time - time of change i.e. 12:53 PM (no need to put the seconds)
VBA Code:
Dim PreviousValue
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Value <> PreviousValue Then
Sheets("Log").Cells(65000, 1).End(xlUp).Offset(1, 0).Value = _
Application.UserName & " changed cell " & Target.Address _
& " from " & PreviousValue & " to " & Target.Value & " at: " & Time & " on: " & Date
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
PreviousValue = Target.Value
End Sub
Any help is appreciated. TIA!