excel 修复Combobox搜索错误运行时间70

pgky5nke  于 2023-10-22  发布在  其他
关注(0)|答案(1)|浏览(101)

我写了一个可搜索的组合框。但是,我得到了一个运行时错误'70':不允许。请救救我!

Private Sub cmb_phanloaitheomucdo_12_Change()
    Dim i As Long
    If Not Comb_Arrow Then
        With Me.cmb_phanloaitheomucdo_12
            .List = Worksheets("Sheet1").Range(Sheet1.Range("B2"), Worksheets("Sheet1").Cells(Rows.Count, "B").End(xlUp)).Value
            .ListRows = Application.WorksheetFunction.Min(4, .ListCount)
            .DropDown
            If Len(.text) Then
                For i = .ListCount - 1 To 0 Step -1
                    If InStr(1, .List(i), .text, vbTextCompare) = 0 Then .RemoveItem i
                Next
                .DropDown
            End If
        End With
    End If
End Sub

Private Sub cmb_phanloaitheomucdo_12_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    If KeyCode = vbKeyReturn Then Me.txt_phanloaieau_13.SetFocus
End Sub
rmbxnbpk

rmbxnbpk1#

如果组合框控件的RowSource属性正在使用中,尝试设置List属性将触发运行时错误70。

Private Sub CommandButton1_Click()
    Me.ComboBox1.List = Range("D1:E3").Value
End Sub

若要解决此问题,请在设置List属性之前添加一行代码以重置RowSource属性,或者在VBE中进行必要的调整。

Private Sub CommandButton1_Click()
    Me.ComboBox1.RowSource = ""
    Me.ComboBox1.List = Range("D1:E3").Value
End Sub

相关问题