ControlSource Property
Applies To
CheckBox control, ComboBox control, ListBox control, OptionButton control, ScrollBar control, SpinButton control, TextBox control, ToggleButton control.
Description
Identifies the data location used to set or store the Value property of a control.
Syntax
object.ControlSource [= String]
The ControlSource property syntax has these parts:
Part | Description |
|
object | Required. A valid object. |
String | Optional. Specifies the worksheet cell linked to the Value property of a control. |
Remarks
The ControlSource property identifies a cell or field; it does not contain the data stored in the cell or field. If you change the Value of the control, the change is automatically reflected in the linked cell or field. Similarly, if you change the value of the linked cell or field, the change is automatically reflected in the Value of the control.
You cannot specify another control for the ControlSource. Doing so causes an error.
The default value for ControlSource is an empty string. If ControlSource contains a value other than an empty string, it identifies a linked cell or field. The contents of that cell or field are automatically copied to the Value property when the control is loaded.
Note If the Value property is Null, no value appears in the location identified by ControlSource.
See Also
ColumnHeads property, Value property.
Example
The following example uses a range of worksheet cells in a ListBox and, when the user selects a row from the list, displays the row index in another worksheet cell. This code sample uses the RowSource, BoundColumn, and ControlSource properties.
To use this example, copy this sample code to the Declarations portion of a form. Make sure that the form contains a ListBox named ListBox1. In the worksheet, enter data in cells A1:E4. You also need to make sure cell A6 contains no data.
Private Sub UserForm_Initialize()
ListBox1.ColumnCount = 5
ListBox1.RowSource = "a1:e4"
ListBox1.ControlSource = "a6"
ListBox1.BoundColumn = 0 'Place the ListIndex into cell a6
End Sub