Vba listbox multicolumn add

Possible duplicate:
Adding items to a multi-column list

MFC VC ++ has two controls, ListBox and ListCtrl . But with VBA, it seems that we only have a ListBox .

I want to create a list with two columns (Company_ID, Company_Name).

Here is what I tried:

  • I created lstbox (ListBox control type)
  • String source type = list of values
  • I take the value from the user from two edit fields, and when the user clicks "add", he should be added to the list with two columns.

In the VBA code procedure, I added the following lines:

 lstbox.ColumnCount = 2 lstbox.AddItem (Company_ID) 

The following code does not work, which is similar to adding a column value:

 lstbox.Column(1,lstbox.ListCount - 1) = Company_name 

This gives an error:

Runtime "424" is required.

Can anyone help with vba code to add multi-column columns to the list.

+7
source share
1 answer

Simplified example (using a counter):

 With Me.lstbox .ColumnCount = 2 .ColumnWidths = "60;60" .AddItem .List(i, 0) = Company_ID .List(i, 1) = Company_name i = i + 1 end with 

Be sure to run the counter with 0, not 1, to populate the list.

+22
source

All Articles