trying to combine automated date and automated user

ctrp44

New Member
Joined
May 31, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
hello

i am trying to get my excel sheet so that each row will show what date that row was edited last and by which user. i can get the two parts to work separately but I cannot get them to work together as it causes the workbook to crash. my code so far is this:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.Count > 1 Then Exit Sub
    If Target.Row < 2 Then Exit Sub
    If Target.Column < 1 Then Exit Sub
    Cells(Target.Row, "I") = Application.UserName
    Cells(Target.Row, "H") = Date
   
End Sub
 
Last edited by a moderator:

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Welcome to the MrExcel board!

When posting vba code in the forum, please use the available code tags. It makes your code much easier to read/debug. My signature block below has more details. I have added the tags for you this time. 😊

You don't need to check if Target.Column < 1 since that is impossible. ;)

Try this

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Cells.CountLarge > 1 Then Exit Sub
  If Target.Row < 2 Then Exit Sub
  Application.EnableEvents = False
  Cells(Target.Row, "H").Resize(, 2).Value = Array(Date, Application.UserName)
  Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,141
Members
453,021
Latest member
Justyna P

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