Link to home
Start Free TrialLog in
Avatar of easycapital
easycapitalFlag for Macao

asked on

Formual to bring windows username (excel 2003)

.. just like when one tracks the changes it displays the name of the user.

but I would like to display it via a formula.

Thanks,
JP
Avatar of Saqib Husain
Saqib Husain
Flag of Pakistan image

You can use a UDF by the function

=usrname()

and the code behind the function is

Function usrname()
usrname = Environ("username")
End Function

Saqib
Avatar of easycapital

ASKER

Should I type some additional code such as Sub...

Thanks,
JP
No Just paste the function...end function in a module

and enter the formula =usrname in the worksheet
sorry, usrname()
I have attached excel workbook. Could you please take a look at it.  I added VBA on sheet 1.  I will be exporting the sheet, so I think the VBA should be there.

Thanks,
JP
Still waiting for the file.

Meanwhile,

- Go to the VBA window
- go to     Insert > Module
- Paste the given code there
- Go to the worksheet
- Paste or type the function

=usrname()

Saqib
Hi Saqib,

Sorry still not work.  I am hard headed today. :)

I forgot the file.

I am using excel 2003.

Thanks,
JP Username-in-formula.xls
I see that you added the code in the module section; so I am assuming that is where I need place the code?

If I was to export sheet one, will it take with it the module code?  That is why I thought I should paste code in the Sheet 1 VBA section.

Thanks,
JP
Ok then use this code

Private Sub Worksheet_Change(ByVal Target As Range)
Range("usrname") = Environ("username")
End Sub

and name the desired cell "usrname" from the insert > name > define

Saqib
Let me think about it.  Using name ranges could cause  a problem is the other sheet has the same name range.

Thanks,
JP
ASKER CERTIFIED SOLUTION
Avatar of Saqib Husain
Saqib Husain
Flag of Pakistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks,
Jp