为什么我无法使用excel VBA更新Listbox的RowSource属性?

时间:2018-06-07 09:17:58

标签: excel vba excel-vba

我的用户窗体与属性窗口的外观如下: Userform

这是我的代码:

With Worksheets("List of Accounts").ListObjects("ListofAccounts").ListColumns(1).Range
    Total_rows_Accounts = .Find(What:="*", _
    After:=.Cells(1), _
    Lookat:=xlPart, _
    LookIn:=xlFormulas, _
    SearchOrder:=xlByRows, _
    SearchDirection:=xlPrevious, _
    MatchCase:=False).Row
End With

If Total_rows_Accounts > 1 Then
    lbxCurrent.RowSource = "List of Accounts!A2:A4"
End If

我的工作表是什么样的:

List of Accounts

错误:

Error

1 个答案:

答案 0 :(得分:7)

您的范围不正确。它应该是lbxCurrent.RowSource = "'List of Accounts'!A2:A4"由于工作表名称中的空格而导致错误