Fix Excel #NAME? Error: USERNAME or USER Function Not Recognized
Question details
The user receives a #NAME? error when attempting to use the =USERNAME() or =USER() functions to automatically insert the current user's name in Excel.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Attempting to automatically extract and display the current user's profile name in a worksheet cell using what is assumed to be a built-in function.
- Observed behavior
- Excel returns a #NAME? error because the USERNAME and USER functions are not built into the software and cannot be recognized.
Ensure you are using the desktop version of Excel for Windows, as the formula workaround relies on local directory paths that may not function correctly in Excel for the Web or macOS.
Use the INFO Function Workaround Formula
Since Excel lacks a built-in USERNAME function, you can combine the INFO function with text manipulation functions to extract the Windows profile name from your local directory path.
The INFO("DIRECTORY") function returns the current directory path, which typically contains the username in Windows (e.g., C:\Users\Username\Documents). By using LET, SUBSTITUTE, and LEFT functions, you can isolate and extract just the username from this string.
Click on the cell where you want the user's name to be displayed.
Type or paste the following formula into the formula bar: =LET(fullpath,INFO("DIRECTORY"),path,SUBSTITUTE(fullpath,"C:\Users\",""),LEFT(path,FIND("\",path)-1))
Press the Enter key to apply the formula. The cell will now display the extracted Windows user profile name.

Create a Custom USERNAME Function using VBA
You can define your own =USERNAME() function by writing a simple Visual Basic for Applications (VBA) macro script.
Easily Manage Advanced Formulas with WPS Spreadsheet
WPS Office Spreadsheet fully supports advanced text manipulation formulas like LET, SUBSTITUTE, and INFO. It also provides excellent compatibility with Excel macros for custom user functions.
- 1. Download WPS Office: Install WPS Office Free from the official website and launch WPS Spreadsheet.
- 2. Open your workbook: Open your existing Excel file (.xlsx) directly in WPS Spreadsheet without losing formatting.
- 3. Apply the workaround formula: Click on any cell and paste the INFO directory formula to automatically extract the username.
- 4. Press Enter: Hit Enter to evaluate the formula seamlessly. WPS Spreadsheet will instantly display the correct username.

Frequently Asked Questions
Why does =USERNAME() return a #NAME? error?
The #NAME? error occurs because Microsoft Excel does not have a built-in function called USERNAME or USER. When you type a function that does not exist, Excel does not recognize the text and returns a naming error.
Is there a built-in function to get the current user in Excel?
No, Excel does not have a native worksheet function specifically designed to return the current user's name. You must use VBA macros or complex text-extraction formulas based on the INFO function to retrieve this information.
Does the INFO('DIRECTORY') workaround work on Excel for Mac?
No, the specific formula relying on 'C:\Users\' is tailored for Windows environments. On a Mac, the directory structure is different, so the SUBSTITUTE and FIND functions will fail to locate the expected path strings.
How do I generally fix a #NAME? error in Excel?
A #NAME? error usually means there is a typo in the function name, a missing quotation mark around a text string, or an unrecognized named range. Double-check your spelling, ensure all text is enclosed in double quotes, and verify that the function is supported in your version of Excel.




