Return the cells referenced by user using RefEdit control of userform in Microsoft Excel

In this article, we will show how to add RefEdit control in userform and refer cell range using it.

In this example, we have created a highlighter userform which we can use for highlighting the cell range with yellow color.

We have taken sample data which consists of name and login hour of team member.

RawData

Adding RefEdit in userform

Add a userform, click on RefEdit control on toolbox and pick and drop control on the userform.

ArrowRefEditControl

Logic explanation

For highlighting the cell, click on the Highlighter button. It will open the userform. Select the range using RefEdit. Click on dash sign for selecting cells.

ArrowHighlighter

For selecting adjacent cells, press Shift key while moving to other cell. For selecting non adjacent cells, press Control key while selecting different cells. Selected cells will be surrounded by dotted lines and cell address will appear in the box.

ArrowSelection

Selected cells will be highlighted in yellow color on pressing the Ok button. Click event of Ok button contains the VBA code for highlighting the selected cells.

ArrowHighlightedCell

 

Please follow below for the code

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

 

If you liked this blog, share it with your friends on Facebook. Also, you can follow us on Twitter and Facebook.

We would love to hear from you, do let us know how we can improve our work and make it better for you. Write to us at info@exceltip.com

Users are saying about us...

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Terms and Conditions of use

The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.

Visit Us On TwitterVisit Us On FacebookVisit Us On Google PlusVisit Us On Youtube