The BoundColumn and TextColumn usage of the VBA control ListBox, the Value and Text usage, and the boundcolumn
When using Excel to write a VBA program, ListBox is used and all its attributes are studied. In fact, this control function is not easy to use, too old, the most important thing is that it does not support the mouse wheel, very difficult to operate, but considering compatibility, still use it.
In fact, it is enough to use ListBox. List to read and write data, while BoundColumn and TextColumn are mainly used to read data? I am not very clear, but it can be used as follows. These two parameters are equivalent to setting the column index (j). You only need to select the row (I) to read the corresponding data List (I, j ). BoundColumn is associated with Value, and TextColumn is associated with Text.
Private Sub commandbutton#click () ListBox1.ListIndex = 0 'select the first row. If it is not selected, no value can be read. ListBox1.BoundColumn = 2' this attribute starts counting from 1, that is, the corresponding column index is 1. The default value is 1 ListBox1.TextColumn = 3. This attribute is counted from 1. That is, the corresponding column index is 2. The default value is-1, if no value is assigned, the data cannot be read. Debug. print "value =" & ListBox1.Value 'output value = 0, 1 Debug. print "text =" & ListBox1.Text 'output text = 0, 2End SubPrivate Sub UserForm_Initialize () dim I As Integer Dim j As Integer ListBox1.ColumnCount = 5' set 5 columns I = 0 While I <10 ListBox1.AddItem j = 0 While j <ListBox1.ColumnCount ListBox1.List (I, j) = CStr (I) & "," & CStr (j) j = j + 1 Wend I = I + 1 WendEnd Sub
Keywords: VBA ListBox BoundColumn TextColumn Value Text description parameter usage Excel