The BoundColumn and TextColumn usage of the VBA control ListBox, the Value and Text usage, and the boundcolumn

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.