Adding items to a multi-column list

How to add items to a list using 2 columns ? It only adds items in the first column if I use ListBox.AddItem . I want to add elements to the 2nd column too. Thanks!

+7
source share
3 answers

Using the List property.

 ListBox1.AddItem "foo" ListBox1.List(ListBox1.ListCount - 1, 1) = "bar" 
+19
source

There is another way to achieve this: -

 Private Sub UserForm_Initialize() Dim list As Object Set list = UserForm1.Controls.Add("Forms.ListBox.1", "hello", True) With list .Top = 30 .Left = 30 .Width = 200 .Height = 340 .ColumnHeads = True .ColumnCount = 2 .ColumnWidths = "100;100" .MultiSelect = fmMultiSelectExtended .RowSource = "Sheet1!C4:D25" End With End Sub 

Here I use the C4: D25 range as a data source for columns. This will cause both columns to be filled with values.

The properties are self-evident. You can explore other parameters by using DrawBox in UserForm and using the "properties window (F4)" to play with the parameters.

+2
source

select propety

String Source Type => List of Values

The code:

ListbName.ColumnCount = 2

ListbName.AddItem "value column1; value column2"

-5
source

All Articles