VBA - Code That Will Log Cell Change Record By A Range And Log It

tzcoding

New Member
Joined
Mar 17, 2023
Messages
8
Office Version
  1. 2016
Platform
  1. Windows
Situation: I have this VBA code that logs any change that is made in the excel sheet and that great; but i need it modified. The plan is to use this in one column as a master change log. But i need a sepret one that will log the window user ID / DATE / Time and lock it to the ROW they edited. So if i change column A the info will be logged in column B.




VBA Code:
Private Sub Worksheet_Change(ByVal Target As range)
    '***************************************************************************************
    'purpose:   This will log any changes to the excel sheet in coulmn AG
    'Last Rev: 03/20/2023
    '***************************************************************************************
  If Not Intersect(Target, range("A:AF")) Is Nothing Then
    With Application
    .EnableEvents = False
    Cells(Rows.Count, "AG").End(xlUp).Offset(1).Value = .UserName & " has modified column " & Split(Target.Address, "$")(1) & " row " & Target.Cells(1, 1).Row & " at " & Format(Now, "dd-mm-yyyy hh:mm AM/PM")
    .EnableEvents = True
    End With
  End If
End Sub
 

Attachments

  • 2023-03-20 11_21_15-News and interests.png
    2023-03-20 11_21_15-News and interests.png
    19.3 KB · Views: 24

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
This code will work. But what if someone changes column B?
VBA Code:
Private Sub Worksheet_Change(ByVal Target As range)
    '***************************************************************************************
    'purpose:   This will log any changes to the excel sheet in coulmn AG
    'Last Rev: 03/20/2023
    '***************************************************************************************
  If Not Intersect(Target, range("A:AF")) Is Nothing Then
    With Application
    .EnableEvents = False
    Cells(Rows.Count, Target.Column+1).End(xlUp).Offset(1).Value = .UserName & " has modified column " & Split(Target.Address, "$")(1) & " row " & Target.Cells(1, 1).Row & " at " & Format(Now, "dd-mm-yyyy hh:mm AM/PM")
    .EnableEvents = True
    End With
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

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