Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show current user name in a cell?

In most of the online resource I can find usually show me how to retrieve this information in VBA. Is there any direct way to get this information in a cell?

For example as simple as =ENVIRON('User') (which did not work)

like image 443
Anthony Kong Avatar asked Aug 03 '11 22:08

Anthony Kong


People also ask

How do I find the username of a cell in Excel?

1. Press Alt + F11 keys to enable Microsoft Visual Basic for Applications window, click Insert > Module, then copy and paste below VBA code to the Module window. VBA: Insert username. You can change the range A1: D5 in VBA code to meet your need.

Where is the active cell name displayed?

The name box is the box at left end of the formula bar that identifies the selected cell, chart item, or drawing object. The Name Box displays the cell reference of the active cell. The Name Box can also be used to assign names to cells or ranges of cells.

How do I get the current worksheet name?

To get the current worksheet's name, you can use the function with or without the optional reference argument, referring to any cell on the current tab. You can also get information about any other worksheet by referring to a cell on that sheet.


2 Answers

Based on the instructions at the link below, do the following.

In VBA insert a new module and paste in this code:

Public Function UserName()
    UserName = Environ$("UserName")
End Function

Call the function using the formula:

=Username()

Based on instructions at:

https://support.office.com/en-us/article/Create-Custom-Functions-in-Excel-2007-2f06c10b-3622-40d6-a1b2-b6748ae8231f

like image 174
Jon Egerton Avatar answered Oct 18 '22 04:10

Jon Egerton


Without VBA macro, you can use this tips to get the username from the path :

=MID(INFO("DIRECTORY"),10,LEN(INFO("DIRECTORY"))-LEN(MID(INFO("DIRECTORY"),FIND("\",INFO("DIRECTORY"),10),1000))-LEN("C:\Users\"))
like image 11
sangorys Avatar answered Oct 18 '22 04:10

sangorys