1

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 toValue 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?

John Smith
  • 7,243
  • 6
  • 49
  • 61
  • 1
    djikay's answers appears to be correct. Also, it appears that the syntax you were using would be correct in Access. I'm sure there is a reason for the difference, but it is a bit irritating. – dennythecoder Jul 12 '14 at 17:15

1 Answers1

3

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.

Community
  • 1
  • 1
djikay
  • 10,450
  • 8
  • 41
  • 52
  • To add to this, it should be done on the userform Initialize event. works perfect though. You can also add single values using the .addItem method.. Just found this out. Thanks. – John Smith Jul 12 '14 at 17:22
  • `RowSource` actually is usable in Excel. The syntax is a string address, e.g., `Me.ComboBox1.RowSource = "A1:A10"`, which will use that range in the ActiveSheet. RowSource is generally not the way to go, but it's the only way to include column headers. RowSourceType does seem to be unusable, so I"m not sure why it's there. – Doug Glancy Jul 12 '14 at 18:42
  • @DougGlancy: Good to know, thanks. Edited my answer so others don't get confused. – djikay Jul 12 '14 at 18:44
  • You bet. Changed my "-" to a "+". List is the way to go. – Doug Glancy Jul 12 '14 at 18:49