简体   繁体   中英

Assigning values to Combo box in excel VBA

I am trying to set the values of the combo box to 0, 1, and 2 (hard coded values and not a cell reference) but it does not seem to work. I have tried setting the RowSourceType" to 1 and to Value List`, but I am getting compile errors every time. For example, the following code does not work:

Private Sub UserForm_Initialize()
Me.errorComboBox.RowSourceType = "Value List"
Me.errorComboBox.RowSource = "0;1;2"
End Sub

or

Private Sub UserForm_Initialize()
Me.errorComboBox.RowSourceType = 1
Me.errorComboBox.RowSource = "0;1;2"
End Sub

I am getting errors on the RowSourceType line for both. How can I do this?

To statically populate the list of a combo box in Excel, try something like this:

Me.errorComboBox.List = Array("0", "1", "2")

This SO question contains links and other examples to achieve what you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM