Username Date & Time

Spraggs

Well-known Member
Joined
Jan 19, 2007
Messages
704
Evening,
I've got a worksheet where I want to enter the username, date & time in columns CA, CB & CC whenever a cell is altered in the corresponding column of range B6:BK52.
i.e. If cell F12 is altered then the username, date & time to be entered in CA12, CB12 & CC12. How can this be done?

Thanks Jase
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Spaggs, try this in Worksheet module.

Code:
[/FONT]
[FONT=Courier New]Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B6:BK52")) Is Nothing Then
 Cells(Target.Row, "CA").Value = Application.UserName
 Cells(Target.Row, "CB").Value = Date
 Cells(Target.Row, "CC").Value = Time
End If
End Sub
 
Upvote 0
Are the cells in the range B6:BK52 altered by someone entering values into them or because they contain formulae whose values might change as a result of the worksheet being recalculated?
 
Upvote 0
Pedie,
Brilliant, thank you.

Thanks Ruddles. Seeing that Pedie's answer works I think answers your question. Thanks all the same.
 
Upvote 0
Yes, she was seconds ahead of me on the Enter key!
 
Upvote 0
Are you using this on a corporate network and/or for auditing purposes?

The reason i ask is Application.username is manually set by the user and could be Mickey Mouse if the user wanted it to be.

You could use something like:
Code:
Environ("username")
- But Environ isn't always reliable. It varies from PC to PC.

If you are working on an Active Directory network, another way would be to do something like:
Module:
Code:
Option Explicit

Public Declare Function apiGetUserName _
               Lib "advapi32.dll" _
               Alias "GetUserNameA" ( _
               ByVal lpBuffer As String, _
               nSize As Long) As Long

Public Function fOSUserName() As String
 Dim lngLen As Long, lngX As Long
 Dim strUserName As String
 
 strUserName = String$(254, 0)
 lngLen = 255
 lngX = apiGetUserName(strUserName, lngLen)
 If lngX <> 0 Then fOSUserName = Left$(strUserName, lngLen - 1) Else fOSUserName = ""
 fOSUserName = UCase(fOSUserName)
End Function

Worksheet would be as pedie suggested but with the function instead:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 If Not Intersect(Target, Range("B6:BK52")) Is Nothing Then
  Cells(Target.Row, "CA").Value = fOSUserName
  Cells(Target.Row, "CB").Value = Date
  Cells(Target.Row, "CC").Value = Time
 End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,545
Messages
6,179,432
Members
452,915
Latest member
hannnahheileen

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