且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

填充多个组合框会使VBA用户窗体变慢

更新时间:2023-12-06 12:11:16

代替

ComboBox3.List = tsheet.Range("A2:l" & 
Worksheets("Players").Cells(Rows.Count, 1).End(xlUp).Row).Value

使用类似这样的内容(将Arr声明为Variant):-

use something like this (declare Arr as Variant):-

Arr = tsheet.Range("A2:l" & 
Worksheets("Players").Cells(Rows.Count, 1).End(xlUp).Row).Value
' add your extra rows to the array here, followed by
ComboBox3.List = Arr

创建一个循环,而不是重复相同的代码40次.

Instead of repeating the same code 40 times, create a loop.

For i = 1 to 40
    Cbx = Me.Controls("ComboBox" & Cstr(i))
    ' then manipulate Cbx as you have done.
Next I

最后,既然您的40个组合框都相同,为什么不只用1个组合框呢?您可以逐行移动它,让用户进行选择,然后将选择转移到出现在退出"时Cbx位置的文本框.再次单击Tbx时,它会被Cbx代替,以便您可以再次访问该列表.

Finally, since your 40 comboboxes are all the same, why not make do with only 1? You can move it around from row to row, let the user make his selection and transfer that selection to a textbox that appears in the place of the Cbx on Exit. When you click on the Tbx again it is substituted by the Cbx so that you have access to the list again.