目前我正在制作带有40个组合框的用户窗体,它们都具有相同的列表。我的问题是填充所有这些组合框的使userform.show
缓慢。在这些组合框中填充的列表是一个非常长的列表(46542行和列表长度可能会有所不同),该列表包含3列。填充多个组合框使VBA用户窗体变慢
我一直在与CONCATENATE鬼混整个名单,但这并没有太大的改变。另外,因为在选择行号时,我需要在组合框中选择的值与组合框中的所有3列进行CONCATENATE。 1,而不是在comboxbox文本框中只写入第1列,它将返回所有3列,这意味着我实际上有4列,其中第一列是CONCATENATE并隐藏在下拉列表中。
所以我的问题是,有没有办法让这个过程更轻?
所以这里是代码:
Private Sub UserForm_Initialize()
Set tsheet = ThisWorkbook.Sheets("Players")
Dim v As Variant, i As Long
v = tsheet.Range("A2:l" & Worksheets("Players").Cells(Rows.Count,
1).End(xlUp).Row).Value
With Me.ComboBox1
.RowSource = ""
.ColumnCount = 4
.BoundColumn = 2
.ColumnWidths = "1;50;50;50" 'Hide first column in dropdown
For i = LBound(v) To UBound(v)
.AddItem v(i, 1) & " " & v(i, 2) & " " & v(i, 3)
.List(.ListCount - 1, 1) = v(i, 1)
.List(.ListCount - 1, 2) = v(i, 2)
.List(.ListCount - 1, 3) = v(i, 3)
Next i
End With
With Me.ComboBox2
.RowSource = ""
.ColumnCount = 4
.BoundColumn = 2
.ColumnWidths = "1;50;50;50" 'Hide first column in dropdown
For i = LBound(v) To UBound(v)
.AddItem v(i, 1) & " " & v(i, 2) & " " & v(i, 3)
.List(.ListCount - 1, 1) = v(i, 1)
.List(.ListCount - 1, 2) = v(i, 2)
.List(.ListCount - 1, 3) = v(i, 3)
Next i
End With
此代码的推移,直到它击中combox40
我的旧代码是工作非常快,但它不具备这是串联列
ComboBox3.ColumnWidths = "50;50;50" 'COLUMN WITH OF LISTBOX
ComboBox3.ColumnCount = 3
'COLUMN NUMBER OF LISTBOX
ComboBox3.List = tsheet.Range("A2:l" &
Worksheets("Players").Cells(Rows.Count, 1).End(xlUp).Row).Value
没有定义'tsheet'然后在代码中使用'Worksheets(“Players”)'....使用'tsheet' – jsotola
没有必要定义'.RowSource''.ColumnCount''.BoundColumn'运行时的'.ColumnWidths'属性....这些值与工作簿一起保存....将它们设置为一个单独的子程序,只运行一次,然后保存该工作簿。如果您想对这些值进行任何更改,请重新运行子文件 – jsotola