writing to a cell current users name

Joe C

Well-known Member
Joined
Oct 17, 2002
Messages
841
How do you write to a cell the current users login name?
I created a series of macros to allow users to update data from pivot table data and then rerun analysis. I take the bad data to a dump sheet and would like to record who selected in case anyone questions why data was removed.
 

Some videos you may like

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Iridium

Well-known Member
Joined
Jul 15, 2002
Messages
2,831
Something Colo wrote a while ago to use as an example:

Code:
Option Explicit

Private Declare Function WNetGetUser Lib "mpr.dll" Alias "WNetGetUserA" _
                         (ByVal lpName As String, _
                          ByVal lpUserName As String, _
                          lpnLength As Long) As Long

Private Const NO_ERROR = 0
Private Const ERROR_NOT_CONNECTED = 2250&
Private Const ERROR_MORE_DATA = 234
Private Const ERROR_NO_NETWORK = 1222&
Private Const ERROR_EXTENDED_ERROR = 1208&
Private Const ERROR_NO_NET_OR_BAD_PATH = 1203&

Sub WinUsername()
    Dim strBuf As String, lngUser As Long, strUn As String
    strBuf = Space$(255) '//Clear buffer
    lngUser = WNetGetUser("", strBuf, 255)
    If lngUser = NO_ERROR Then
        strUn = Left(strBuf, InStr(strBuf, vbNullChar) - 1)
        Sheets("Sheet1").Range("A11") = "User Name is  " & strUn
    Else
        Sheets("Sheet1").Range("A11") = "Error :" & lngUser
    End If
End Sub

An alternative: http://j-walk.com/ss/excel/tips/tip94.htm

Or have a search of the board on 'environ("username")' (without the single quotes)
HTH
 

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
How about:
Code:
Sub UserName()
    Dim CurrentUserName As String
        CurrentUserName = Environ("Username")
    Sheets("Sheet1").Range("A1") = CurrentUserName
End Sub
Hope that helps,

Smitty
 

Joe C

Well-known Member
Joined
Oct 17, 2002
Messages
841
Pennysaver was just what I needed. Thanks to all contributers.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,561
Messages
5,596,849
Members
414,107
Latest member
Tigretto

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
Top