log user who made a change to a cell

jdhfch

Board Regular
Joined
Jan 25, 2018
Messages
83
Office Version
  1. 365
Platform
  1. Windows
Hi,

Please can someone help?

I am looking to log in a cell the last user that made the change to a specific cell in a workbook shared on sharepoint.

for example, if someone put a Y in cell N5 called Jonesj, I would like the Jonesj to appear in cell O5?

Is this possible, please?
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Hello, using the Change Event of the worksheet/workbook you want to keep an eye on, you can do something like this

I think you need to have the SharePoint Workbook avaliable/sync on your PC however. I do not know how to access it otherwise.
VBA Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Source As Range) 
  Dim myRange As Range
  Set myRange = ThisWorkbook.Worksheets(1).Range("N5") 
  Dim sharePWb As Workbook
  Set sharePWb = ???
  If Not Intersect(Source, myRange) Is Nothing Then
    sharePWb.Worksheets(1).Range("O5").Value2 = Application.UserName
  End If
End Sub
 
Upvote 0
Hello, using the Change Event of the worksheet/workbook you want to keep an eye on, you can do something like this

I think you need to have the SharePoint Workbook avaliable/sync on your PC however. I do not know how to access it otherwise.
VBA Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Source As Range)
  Dim myRange As Range
  Set myRange = ThisWorkbook.Worksheets(1).Range("N5")
  Dim sharePWb As Workbook
  Set sharePWb = ???
  If Not Intersect(Source, myRange) Is Nothing Then
    sharePWb.Worksheets(1).Range("O5").Value2 = Application.UserName
  End If
End Sub
Thank you.

I am not sure if I am doing something wrong here. The workbook is held on my PC and is called Discounted Orders.xlsm - I have put this into the Set sharePWb = ??? par of your code, but it isn't working. I am also wanting it to not just be N5 & O5, it would be N6 and O6 etc as well as changes are made to them?

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Source As Range)
Dim myRange As Range
Set myRange = ThisWorkbook.Worksheets(2).Range("N5")
Dim sharePWb As Workbook
Set sharePWb = "Discounted_orders.xlsm"
If Not Intersect(Source, myRange) Is Nothing Then
sharePWb.Worksheets(2).Range("O5").Value2 = Application.UserName
End If
End Sub
 
Upvote 0
Hello again,

My apologies, the code was not very clear, and also incorect as it was not opening the file to write in it.

Please find below a correction.
VBA Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Source As Range)
  Dim myRange As Range
  ' you enter here the range to be logged if modified
  Set myRange = ThisWorkbook.Worksheets(1).Range("N5:N6")
  Dim shareWbPath As String
  ' you enter here the local path to the synced file on your PC
  ' you need to put the full path
  shareWbPath = "C:\Users\XXX\OneDrive\Discounted_orders.xlsm"
  Application.ScreenUpdating = False
  If Not Intersect(Source, myRange) Is Nothing Then
    With Workbooks.Open(shareWbPath)
      ' if i understood corectly, you put the name of the user
      ' 2 columns to the right on the shared workbook (it's the offset part)
      .Worksheets(2).Range(Intersect(Source, myRange).Address).Offset(0, 2).Value2 = Application.UserName
      .Save
      .Close
    End With
  End If
  Application.ScreenUpdating = True
End Sub
However opening and closing the file at each "successful" modification can be quite heavy. Maybe it is better to send all modifications to the shared workbook once the current file is closed, or saved. But it is just my opinion. I mean it is already a tricky question when the Review > Show changes tab exists...
 
Upvote 0
Solution
Hello again,

My apologies, the code was not very clear, and also incorect as it was not opening the file to write in it.

Please find below a correction.
VBA Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Source As Range)
  Dim myRange As Range
  ' you enter here the range to be logged if modified
  Set myRange = ThisWorkbook.Worksheets(1).Range("N5:N6")
  Dim shareWbPath As String
  ' you enter here the local path to the synced file on your PC
  ' you need to put the full path
  shareWbPath = "C:\Users\XXX\OneDrive\Discounted_orders.xlsm"
  Application.ScreenUpdating = False
  If Not Intersect(Source, myRange) Is Nothing Then
    With Workbooks.Open(shareWbPath)
      ' if i understood corectly, you put the name of the user
      ' 2 columns to the right on the shared workbook (it's the offset part)
      .Worksheets(2).Range(Intersect(Source, myRange).Address).Offset(0, 2).Value2 = Application.UserName
      .Save
      .Close
    End With
  End If
  Application.ScreenUpdating = True
End Sub
However opening and closing the file at each "successful" modification can be quite heavy. Maybe it is better to send all modifications to the shared workbook once the current file is closed, or saved. But it is just my opinion. I mean it is already a tricky question when the Review > Show changes tab exists...
Thank you - worked perfectly :)
 
Upvote 0

Forum statistics

Threads
1,226,114
Messages
6,189,051
Members
453,522
Latest member
Seeker2025

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