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.
Adding RefEdit in userform
Add a userform, click on RefEdit control on toolbox and pick and drop control on the userform.
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.
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.
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.
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
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 email@example.com
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.