Thread: User Record
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Darren Bartrup[_2_] Darren Bartrup[_2_] is offline
external usenet poster
 
Posts: 36
Default User Record

Actually, scratch that as the formula will update when a different user opens
the workbook.

"Darren Bartrup" wrote:

Enter this code in a normal module:

'http://www.j-walk.com/ss/excel/tips/tip94.htm

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

Function UserName() As String
' Returns the name of the logged-in user
Dim Buffer As String * 100
Dim BuffLen As Long
BuffLen = 100
GetUserName Buffer, BuffLen
UserName = Left(Buffer, BuffLen - 1)
End Function

NB: The PRIVATE DECLARE FUNCTION must be at the top of the module, before
any functions or procedures.

Then use either of these functions to return the logged on username:
=IF($A2="x",username(),"")
or
=IF(INDIRECT(ADDRESS(0,1,3,FALSE),FALSE)="x",usern ame(),"")

The second function will check column A of whichever row you enter the
formula on.