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

AutoSizeSpecifies whether an object automatically resizes to display its entire contents.
AutoTabSpecifies 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.
AutoWordSelectSpecifies whether a word or a character is the basic unit used to extend a selection.
BackColorSpecifies the background color of the object.
BackStyleReturns or sets the background style for an object.
BorderColorSpecifies the color of an object's border.
BorderStyleSpecifies the type of border used.
ControlTipTextSpecifies text that appears when the user briefly holds the mouse pointer over a control without clicking.
DragBehaviorSpecifies whether the system enables the drag-and-drop feature for a TextBox or ComboBox.
EnabledSpecifies whether a control can receive the focus and respond to user-generated events.
EnterFieldBehaviorSpecifies the selection behavior when entering a TextBox or ComboBox.
EnterKeyBehaviorDefines the effect of pressing ENTER in a TextBox.
FontDefines the characteristics of the text used by a control.
ForeColorSpecifies the foreground color of an object
HeightThe height in points.
HelpContextIDThe HelpContextID property associates a specific topic in a custom Microsoft Windows Help file with a specific control.
HideSelectionSpecifies whether selected text remains highlighted when a control does not have the focus.
IMEModeSpecifies 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.
IntegralHeightIndicates whether a ListBox or TextBox displays full lines of text in a list or partial lines.
LeftThe distance between a control and the left of the form that contains it.
LockedSpecifies whether a control can be edited.
MaxLengthSpecifies the maximum number of characters a user can enter in a TextBox or ComboBox.
MouseIconAssigns a custom icon to an object.
MousePointerSpecifies the type of pointer displayed when the user positions the mouse over a particular object.
MultiLineSpecifies whether a control can accept and display multiple lines of text.
PasswordCharSpecifies whether placeholder characters are displayed instead of the characters actually entered in a TextBox.
ScrollBarsSpecifies whether a control, form, or page has vertical scroll bars, horizontal scroll bars, or both.
SelectionMarginSpecifies whether the user can select a line of text by clicking in the region to the left of the text.
SelLengthThe number of characters selected in a TextBox or the text portion of a ComboBox.
SelStartIndicates the starting point of selected text, or the insertion point if no text is selected.
SelTextReturns or sets the selected text of a control.
SpecialEffectSpecifies the visual appearance of an object.
TabIndexSpecifies the position of a single object in the form's tab order.
TabKeyBehaviorDetermines whether tabs are allowed in the edit region.
TabStopIndicates whether an object can receive focus when the user tabs to it.
TagStores additional information about an object.
TextChanges the selected row in a ListBox.
TextAlignSpecifies how text is aligned in a control. Can be any of the fmTextAlign constants.
TopThe distance between a control and the top edge of the form that contains it.
ValueSpecifies the state or content of a given control.
VisibleSpecifies whether an object is visible or hidden.
WidthThe width in points.
WordWrapIndicates whether the contents of a control automatically wrap at the end of a line.

Events

AfterUpdateFires each time the listbox selection changes. This does not fire unless the listbox has its Multi-Select set to Single.
BeforeDragOverOccurs when a drag-and-drop operation is in progress.
BeforeDropOrPasteOccurs when the user is about to drop or paste data onto an object.
BeforeUpdateOccurs before data in a control is changed.
ChangeOccurs when the Value property changes.
DblClickOccurs when the user points to an object and then clicks a mouse button twice.
DropButtonClickOccurs whenever the drop-down list appears or disappears.
EnterOccurs before a control actually receives the focus from a control on the same form.
ErrorOccurs when a control detects an error and cannot return the error information to a calling program.
ExitOccurs immediately before a control loses the focus to another control on the same form.
KeyDownOccurs when the user presses a key on a running form while that form or a control on it has the focus.
KeyPressOccurs when the user presses an ANSI key.
KeyUpOccurs when the user releases a key on a running form while that form or a control on it has the focus.
MouseDownOccurs when the user presses the mouse button.
MouseMoveOccurs when the user moves the mouse.
MouseUpOccurs when the user releases the mouse button.

© 2025 Better Solutions Limited. All Rights Reserved. © 2025 Better Solutions Limited TopPrevNext