How To Return the cells referenced by the user using RefEdit control of user form in Excel?
Tags: toreturnthecellsrefe, vbamacros
Published: 2021-10-13 02:16:15

---
title: How To Return the cells referenced by the user using RefEdit control of user form in Excel?
published: true
date: 2021-10-12 10:00:44 UTC
tags: ToReturnTheCellsRefe,VBAMacros
canonical_url: https://geekexcel.com/how-to-return-the-cells-referenced-by-the-user-using-refedit-control-of-user-form-in-excel/
---

In this blog post, we are going to see how to  **return the cells referenced by the user using RefEdit control of user form** in Excel. Let’s get into this article!! 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 **name and login hour of team member**.

![](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2021/10/Sample-data-22.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://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2021/09/Select-Visual-Basic-9-1024x180.png)<figcaption>Select Visual Basic</figcaption>

- Now, you have to **add RefEdit in user form,** and click on **RefEdit control** on toolbox.

![](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2021/10/Add-RefEdit.png)<figcaption>Add RefEdit</figcaption>

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

```
Option Explicit
Sub running()
UserForm1.Show
End Sub

'Add below code in "Ok" button on userform
Option Explicit
Private Sub CommandButton1_Click()
Dim SelectRange As Range
Dim Address1 As String
On Error GoTo Last
'Get the address from the RefEdit control
Address1 = RefEdit1.Value
'Set the SelectRange Range object to the range specified in the RefEdit control
Set SelectRange = Range(Address1)
'Highlight the selected range in yellow color
SelectRange.Interior.Color = RGB(255, 255, 0)
'Unload the userform.
Unload Me
Last:
End Sub

```

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

![](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2021/10/Save-the-Code-37-1024x788.png)<figcaption>Save the Code</figcaption>

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

![Choose Macro option](https://eadn-wc04-371788.nxedge.io/cdn/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://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2021/10/Run-the-Code-29.png)<figcaption>Run the Code</figcaption>

- After running the macro, for **highlighting the cell** , you have to click on the **Highlighter button** , and it will **open the user form**.

![](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2021/10/UserForn1.png)<figcaption>UserForm1</figcaption>

- Then, you need to **select the range using RefEdit** and click on **dash sign** for selecting cells.
- Now, for **selecting adjacent cells** , you have to **press Shift key** while moving to other cell.
- For **selecting non-adjacent cells** , you need to **press Control key** while selecting different cells and selected cells will be surrounded by **dotted lines and cell address** will appear in the box.

![](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2021/10/Select-the-range.png)<figcaption>Select the range</figcaption>

- Finally,  **selected cells** will be **highlighted in yellow color** on pressing the **Ok button** in Excel.

![](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2021/10/Output-20.png)<figcaption>Output</figcaption>

## Verdict

In the above post, you can learn the simple steps ** ** on how to  **return the cells referenced by the user using RefEdit control of user form** in Excel. Kindly, share your  **feedback**  in the below comment section. Thanks for visiting **[Geek Excel.](https://geekexcel.com/)** Keep Learning!

**Keep Reading:**

- **[Simple Shortcut to Move to the Next Control in MS Excel 365!!](https://geekexcel.com/simple-shortcut-to-move-to-the-next-control-in-ms-excel-365/)**
- **[Easy Shortcut to Move to the Previous Control in Excel 365!!](https://geekexcel.com/easy-shortcut-to-move-to-the-previous-control-in-excel-365/)**
- **[How to Create a Form for Search and Print through VBA in Microsoft Excel?](https://geekexcel.com/how-to-create-a-form-for-search-and-print-through-vba-in-microsoft-excel/)**
- **[Control Word from Excel using VBA in Microsoft Excel 2010](https://geekexcel.com/how-to-control-word-from-excel-using-vba-in-microsoft-excel-2010/)**
- **[How To Control Excel from Word using VBA in Microsoft Excel 2010?](https://geekexcel.com/how-to-control-excel-from-word-using-vba-in-microsoft-excel-2010/)**