RefEdit (ref)
![]() | Ref Edit - This control allows the user to select a range of cells in Excel. |
![]() |
Additional Control / Reference
Name - RefEdit.Ctrl
![]() |
There are a few things to keep in mind when you are using this control
The RefEdit control returns a text string that represents a range address
You can convert this string to a range object using the following statement:
Set objRange = Range(RefEdit.Text)
It is a good idea to initialise this control to display the current selection
RefEdit.Text = ActiveWindow.RangeSelection.Address
Do not always assume that it will always return a valid range address.
The user can also type directly into this control so you need to make sure the value entered is valid.
You cannot assume the selection made is on the same worksheet as the user may select worksheet tabs.
If a different sheet is selected the range is preceded by the name of the sheet
If you only need a single cell you can obtain the top left cell from the range
objCell = Range(RefEdit.Text).Range("A1")
You should always put this control directly onto a userform, do not place it inside any other controls (for example frames)
Never make a userform modeless if it contains a RefEdit control.
RefEdit - http://blogs.msdn.com/gabhan_berry/archive/2008/06/12/net-refedit-control.aspx
RefEdit - http://www.codeproject.com/KB/selection/RefEditControl.aspx
Alternative
Use a regular textbox instead called "txtRefEdit".
Private Sub UserForm_Initialize()
Me.txtRefEdit.DropButtonStyle = fmDropButtonStyleReduce
Me.txtRefEdit.ShowDropButtonWhen = fmShowDropButtonWhenAlways
End Sub
Private Sub txtRefedit_DropButtonClick()
Dim var As Variant
Dim rng As Range
Dim sFullAddress As String
Dim sAddress As String
Me.Hide
On Error Resume Next
var = Application.InputBox("Select the range containing your data", "Label Range", _
Me.txtRefEdit.Text, Me.Left + 2, Me.Top - 86, , , 0)
On Error GoTo 0
If TypeName(var) = "String" Then
CheckAddress CStr(var)
End If
Me.Show
End Sub
Properties
AutoSize | Specifies whether an object automatically resizes to display its entire contents. |
AutoTab | Specifies whether an automatic tab occurs when a user enters the maximum allowable number of characters into a TextBox or the text box portion of a ComboBox. |
AutoWordSelect | Specifies whether a word or a character is the basic unit used to extend a selection. |
BackColor | Specifies the background color of the object. |
BackStyle | Returns or sets the background style for an object. |
BorderColor | Specifies the color of an object's border. |
BorderStyle | Specifies the type of border used. |
ControlTipText | Specifies text that appears when the user briefly holds the mouse pointer over a control without clicking. |
DragBehavior | Specifies whether the system enables the drag-and-drop feature for a TextBox or ComboBox. |
Enabled | Specifies whether a control can receive the focus and respond to user-generated events. |
EnterFieldBehavior | Specifies the selection behavior when entering a TextBox or ComboBox. |
EnterKeyBehavior | Defines the effect of pressing ENTER in a TextBox. |
Font | Defines the characteristics of the text used by a control. |
ForeColor | Specifies the foreground color of an object |
Height | The height in points. |
HelpContextID | The HelpContextID property associates a specific topic in a custom Microsoft Windows Help file with a specific control. |
HideSelection | Specifies whether selected text remains highlighted when a control does not have the focus. |
IMEMode | Specifies the default run time mode of the Input Method Editor (IME) for a control. This property applies only to applications written for East Asia and is ignored in other applications. |
IntegralHeight | Indicates whether a ListBox or TextBox displays full lines of text in a list or partial lines. |
Left | The distance between a control and the left of the form that contains it. |
Locked | Specifies whether a control can be edited. |
MaxLength | Specifies the maximum number of characters a user can enter in a TextBox or ComboBox. |
MouseIcon | Assigns a custom icon to an object. |
MousePointer | Specifies the type of pointer displayed when the user positions the mouse over a particular object. |
MultiLine | Specifies whether a control can accept and display multiple lines of text. |
PasswordChar | Specifies whether placeholder characters are displayed instead of the characters actually entered in a TextBox. |
ScrollBars | Specifies whether a control, form, or page has vertical scroll bars, horizontal scroll bars, or both. |
SelectionMargin | Specifies whether the user can select a line of text by clicking in the region to the left of the text. |
SelLength | The number of characters selected in a TextBox or the text portion of a ComboBox. |
SelStart | Indicates the starting point of selected text, or the insertion point if no text is selected. |
SelText | Returns or sets the selected text of a control. |
SpecialEffect | Specifies the visual appearance of an object. |
TabIndex | Specifies the position of a single object in the form's tab order. |
TabKeyBehavior | Determines whether tabs are allowed in the edit region. |
TabStop | Indicates whether an object can receive focus when the user tabs to it. |
Tag | Stores additional information about an object. |
Text | Changes the selected row in a ListBox. |
TextAlign | Specifies how text is aligned in a control. Can be any of the fmTextAlign constants. |
Top | The distance between a control and the top edge of the form that contains it. |
Value | Specifies the state or content of a given control. |
Visible | Specifies whether an object is visible or hidden. |
Width | The width in points. |
WordWrap | Indicates whether the contents of a control automatically wrap at the end of a line. |
Events
AfterUpdate | Fires each time the listbox selection changes. This does not fire unless the listbox has its Multi-Select set to Single. |
BeforeDragOver | Occurs when a drag-and-drop operation is in progress. |
BeforeDropOrPaste | Occurs when the user is about to drop or paste data onto an object. |
BeforeUpdate | Occurs before data in a control is changed. |
Change | Occurs when the Value property changes. |
DblClick | Occurs when the user points to an object and then clicks a mouse button twice. |
DropButtonClick | Occurs whenever the drop-down list appears or disappears. |
Enter | Occurs before a control actually receives the focus from a control on the same form. |
Error | Occurs when a control detects an error and cannot return the error information to a calling program. |
Exit | Occurs immediately before a control loses the focus to another control on the same form. |
KeyDown | Occurs when the user presses a key on a running form while that form or a control on it has the focus. |
KeyPress | Occurs when the user presses an ANSI key. |
KeyUp | Occurs when the user releases a key on a running form while that form or a control on it has the focus. |
MouseDown | Occurs when the user presses the mouse button. |
MouseMove | Occurs when the user moves the mouse. |
MouseUp | Occurs when the user releases the mouse button. |
© 2025 Better Solutions Limited. All Rights Reserved. © 2025 Better Solutions Limited TopPrevNext