Event Log

Brabed

Board Regular
Joined
Oct 27, 2005
Messages
54
I am looking to have record of when the values of certain cells change so that I could go back and reference. I am thinking of having one worksheet show all the cell changes on another worksheet. How do I do this? Thanks in advance.....
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Here is some code. Right click the sheet tab and View code - copy & paste it there. You need another sheet called "Sheet2" for the log.

I have not tested this in use (Don't know that I would want to :eek: )
I have included code to get the user login name because experience shows that Application.UserName is not always accurate. It comes from Tools/Options which is not always updated.
Code:
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Dim LogSheet As Worksheet
Dim LogRow As Long
Dim OldValue As Variant
Dim NewValue As Variant
Dim User As String
'====================================================================

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    Set LogSheet = Worksheets("Sheet2")
    LogRow = LogSheet.Range("A65536").End(xlUp).Row + 1
    NewValue = Target.Value
    '----------------------------------------------------
    '- enter log details
    LogSheet.Cells(LogRow, "A").Value = Now             ' date
    LogSheet.Cells(LogRow, "B").Value = MyUserName      ' user
    LogSheet.Cells(LogRow, "C").Value = Target.Address  ' cell ref
    LogSheet.Cells(LogRow, "D").Value = OldValue
    LogSheet.Cells(LogRow, "E").Value = NewValue
End Sub
'==================================================================
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
    OldValue = ActiveCell.Value
End Sub

'==================================================================
'- function to get server login name
'- or Application.Username if not logged in
'==================================================================
Private Function MyUserName() As String
    Dim lngLen As Long, lngX As Long
    Dim strUserName As String
    strUserName = String$(254, 0)
    lngLen = 255
    lngX = apiGetUserName(strUserName, lngLen)
    If (lngX > 0) Then
        MyUserName = Left$(strUserName, lngLen - 1)
    Else
        MyUserName = Application.UserName
    End If
End Function
'==================================================================
 
Upvote 0

Forum statistics

Threads
1,214,915
Messages
6,122,212
Members
449,074
Latest member
cancansova

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top