Need VBA to capture who and when

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have looked at http://www.mcgimpsey.com/excel/timestamp.html and it gave me
some ideas and parts to use, but it isn't all that I need.

I would like to on a worksheet change event:

1) on the same row as the cell where the change was made, insert the
timestamp in column X
2) on the same row as the cell where the change was made, insert the userid
of the person who made the change in column y

Also, what happens to a change event when calc is off? Does XL queue up the
changes and then apply them one at a time once Calc is pressed?

Thanks for any help. -Russ
 
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
rw = Target.Row
Cells(rw, "X").Value = Now
Cells(rw, "Y").Value = Environ("UserName")
Application.EnableEvents = True
End Sub
 
Very cool Gary! I appreciate pithy code. Thanks very much for your help!!!

Russ
 
Gary,

This works great if someone is doing a simple edit. I have found two ways
where it fails.

1) If I copy a value and paste that value to 6 rows, it only creates the
audit information into the first destination row.
2) If I change a value from a data validation list it doesn't generate the
audit information.

How would I expand your code to cover these two possibilities as well?

thanks,

Russ
 
Russ,

I would suggest that you limit the action to a specific column (in this case, the A:A does that).
Change A:A to the column of interest.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim myCell As Range
If Intersect(Target, Range("A:A")) Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each myCell In Target
rw = myCell.Row
Cells(rw, "X").Value = Now
Cells(rw, "Y").Value = Environ("UserName")
Next myCell
Application.EnableEvents = True
End Sub

Works for me, for all types of changes.


HTH,
Bernie
MS Excel MVP
 
For Each myCell In Target
should have been
For Each myCell In Intersect(Target, Range("A:A"))

Sorry,
Bernie
MS Excel MVP
 
Bernie,

This is cool man. I already have a named range for the data I want audited.
Simply switching that range into your code and it is sweet! Thanks very
much!
 
This is cool man. I already have a named range for the data I want audited.
Simply switching that range into your code and it is sweet! Thanks very
much!

You're welcome!

Bernie
 
You should have stayed in the original thread.
Right click the sheet tab>view code>copy/paste
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top