在Excel工作表上填充第二列+列表框

我有一个Excel 2007工作表上的ActiveX列表框。 我想直接填充它,而不是通过将其RowSource属性指向一个范围,因为没有范围具有所需的值。

列表框的ColumnCount设置为2.我将ColumnWidths设置为“20; 20”,现在它返回:20 pt; 20 pt

所以据我所知,列表框中的两列应该是可用的,对吗?

填充第一列是没有问题的:

activesheet.lstApplyCurves.List = array("Select All","Deselect All","aaa","bbb","ccc") 

(要么)

 activesheet.lstApplyCurves.additem activesheet.lstApplyCurves.List(0,0) = "Col1, Row1" 

但是,我如何填充第2列? 我得到一个错误380(“无法设置列表属性。无效的属性值。”):

 activesheet.lstApplyCurves.List(0,1) = "Col2, Row1" 

FWIW我也试过这个,但得到同样的错误:

 activesheet.lstApplyCurves.List(1,1) = "Col2, Row2" 

所以…我如何在第二列设置数值?

更新:

除了下面的答案,FWIW我还发现可以将一个multidimensional array分配给List属性,这是更快的:

 Dim ArrayToListbox() As Variant ReDim ArrayToListbox(0 To 4, 0 To 2) ArrayToListbox(0, 0) = "Select All" ArrayToListbox(1, 0) = "Deselect All" ArrayToListbox(2, 0) = "Row1-Col1" ArrayToListbox(2, 1) = "Row1-Col2" ArrayToListbox(2, 2) = "Row1-Col3" ArrayToListbox(3, 0) = "Row2-Col1" ArrayToListbox(3, 1) = "Row2-Col2" ArrayToListbox(3, 2) = "Row2-Col3" ArrayToListbox(4, 0) = "Row3-Col1" ArrayToListbox(4, 1) = "Row3-Col2" ArrayToListbox(4, 2) = "Row3-Col3" '"(" & Join(Array("a", "b", "c"), "|") & ")" ActiveSheet.lstApplyCurves.Clear ActiveSheet.lstApplyCurves.ColumnCount = 3 ActiveSheet.lstApplyCurves.List = ArrayToListbox 

这对我有用。 如果以下操作在您的系统上不起作用,请删除列表框并重新创build它,然后再次尝试此代码。

 Private Sub CommandButton1_Click() With ListBox1 .Clear .ColumnCount = 2 For i = 1 To 2 .AddItem .List(i - 1, 0) = "Col1, Row" & i .List(i - 1, 1) = "Col2, Row" & i Next i End With End Sub 

在这里输入图像描述