VBA Code To Timestamp & Username For Anything That Changes In a Select Range

tzcoding

New Member
Joined
Mar 17, 2023
Messages
8
Office Version
  1. 2016
Platform
  1. Windows
I have both sides of the code but do not know how to join them together. One part of the cod will pull the Windows user name but not work with a selected range and not work with if there is a change in that range. The other part works with with timestamping when ever there is a change within a selected ranch and logs that day.

Timestamp Code:
VBA Code:
Public Function ModDate(Reference As Range)
Dim cell As Range

For Each cell In Reference

    ModDate = Format(Now, "dd-mm-yyyy hh:mm AM/PM")

Next cell

End Function

Windows Username:
Code:
Public Function UserName()


    UserName = Environ$("UserName")

End Function


Does anyone know how to join the two into one?
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
This code will log the changes in column Z. This is an event, which means, it will fire up automatically each time a change occures in the sheet.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  With Application
  .EnableEvents = False
  Cells(Rows.Count, "Z").End(xlUp).Offset(1).Value = .UserName & " has modified cell: " & Target.Address & " at " & Format(Now, "dd-mm-yyyy hh:mm AM/PM")
  .EnableEvents = True
  End With
End Sub
 
Upvote 1
This code will log the changes in column Z. This is an event, which means, it will fire up automatically each time a change occures in the sheet.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  With Application
  .EnableEvents = False
  Cells(Rows.Count, "Z").End(xlUp).Offset(1).Value = .UserName & " has modified cell: " & Target.Address & " at " & Format(Now, "dd-mm-yyyy hh:mm AM/PM")
  .EnableEvents = True
  End With
End Sub
This is great i just have a question. I know that it will log the information in column "Z" and i can change it to AE for my target log column. That part is clear to me. The columns i need it to look at are 'A'-'AD' and it has to do it row by row. So if i change anything in columns A'-'AD' row 4 it puts the log in AE row 4.
 
Upvote 0
I think this is what you want. Bare in mind that this will display only the first row index when multiple rows modified.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Not Intersect(Target, Range("A:AD")) Is Nothing Then
    With Application
    .EnableEvents = False
    Cells(Rows.Count, "AE").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
Solution

Forum statistics

Threads
1,223,884
Messages
6,175,177
Members
452,615
Latest member
bogeys2birdies

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