以下是我创建的代码:
Private Sub UserForm_Activate()
Dim Total_rows_PU As Long
Total_rows_PU = Workbooks("Revised-Payroll (VBA Copy).xlsm").Worksheets("Payroll Update").Range("A" & Rows.Count).End(xlUp).Row
Me.cbxName.List = Worksheets("Payroll Update").Range("A2:A" & Total_rows_PU)
End Sub
这是我收到的错误:
考虑下面的答案后的工作解决方案:
Private Sub UserForm_Initialize()
Total_rows_PU = Workbooks("Revised-Payroll (VBA Copy).xlsm").Worksheets("Payroll Update").Range("A" & Rows.Count).End(xlUp).Row
Dim cell As Range
For Each cell In Range("A2:A" & Total_rows_PU)
Me.cbxName.AddItem cell.Value
Next
End Sub
答案 0 :(得分:1)
这是填充组合框的正确方法:
List(Trunk("123"), Trunk("456"))
.foldRight(Nil: MyList[Trunk])((next, acc) => Cons(next, acc))
它使用范围Private Sub UserForm_Initialize()
Dim cell As Range
For Each cell In Range("A1:A9")
Me.ComboBox1.AddItem cell.Value
Next
End Sub
中的单元格的值填充组合框(您必须指定自己的值)。以下是它的工作原理:
值表示单元格地址:)
当然,@ TotsieMae指出了很多好资源 - 我建议他们:)