How does Macro return the user name and computer name in Excel?
Tags: macrotoreturntheuser, vbamacros
Published: 2021-10-01 02:22:10

---
title: How does Macro return the user name and computer name in Excel?
published: true
date: 2021-09-29 07:07:00 UTC
tags: MacroToReturnTheUser,VBAMacros
canonical_url: https://geekexcel.com/how-does-macro-return-the-user-name-and-computer-name-in-excel/
---

In this tutorial, we will guide you on how does **macro return the username and computer name** in Excel. Let’s get them below!! Get an official version of MS Excel from the following link: **[https://www.microsoft.com/en-in/microsoft-365/excel](https://www.microsoft.com/en-in/microsoft-365/excel)**

## Example

- Firstly, you need to **create a sample data** with **computer name**  **in cell B10 and username in cell B11**.

![](https://geekexcel.com/wp-content/uploads/2021/09/Sample-data-47.png)<figcaption>Sample data</figcaption>

- In the Excel Worksheet, you have to go to the  **Developer Tab.**
- Then, you need to ** ** select the  **Visual Basic**  option under the  **Code**  section.

![Select Visual Basic](https://geekexcel.com/wp-content/uploads/2021/09/Select-Visual-Basic-9-1024x180.png)<figcaption>Select Visual Basic</figcaption>

- Now, you have to  **copy and paste the code**  given below.

```
Sub GetComputerUserName()

Dim ComputerName, UserName As String

'Getting computer name
ComputerName = Environ("computername")

'Getting user name
UserName = Environ("username")

'Assigning value to cell C10 and C11
Range("C10").Value = ComputerName
Range("C11").Value = UserName

End Sub

```

- You need to  **save the code**  by selecting it and then  **close the window**.

![](https://geekexcel.com/wp-content/uploads/2021/09/Save-the-Code-93.png)<figcaption>Save the Code</figcaption>

- Again, you have to go to the  **Excel Spreadsheet** , and click on the  **Developer Tab**.
- You need to choose the  **Macros option**  in the Code section.

![Choose Macro option](https://geekexcel.com/wp-content/uploads/2021/09/Choose-Macro-option-11-1024x184.png)<figcaption>Choose Macro option</figcaption>

- Now, you have to make sure that your  **macro name is selected**  and click the  **Run ** button.

![](https://geekexcel.com/wp-content/uploads/2021/09/Run-the-Code-60.png)<figcaption>Run the Code</figcaption>

- Finally, you will receive  **username and computer name**  using VBA in Excel.

![](https://geekexcel.com/wp-content/uploads/2021/09/Output-44.png)<figcaption>Output</figcaption>

## Bottom-Line

We hope that this tutorial gives you guidelines on how does **macro return the username and computer name** in Excel. Please leave a comment in case of any  **queries,**  and don’t forget to mention your valuable  **suggestions**  as well. Thank you so much for Visiting Our Site!! Continue learning on **[Geek Excel](https://geekexcel.com/)!! **Read more on [**Excel Formulas**](https://geekexcel.com/excel-formula/) **!!**

**Read Also:**

- **[how to Convert Small Letters into Uppercase for Some Columns in VBA?](https://geekexcel.com/how-to-convert-small-letters-into-uppercase-for-some-columns-in-vba/)**
- **[How to use Excel LOWER Function in Office 365? – Simple Steps!!](https://geekexcel.com/how-to-use-lower-function-in-microsoft-excel-365/)**
- **[How to Convert Selection to UPPERCASE using Macros in Excel?](https://geekexcel.com/how-to-convert-selection-to-uppercase-using-macros-in-excel/)**
- **[How to Open a Blank File in Excel ? – A Complete Guide!!](https://geekexcel.com/open-blank-excel-file/)**
- **[How to Use Excel UPPER Function in Office 365? – Easy Steps!!](https://geekexcel.com/how-to-use-upper-function-in-microsoft-excel-365/)**