我写了一个可搜索的组合框。但是,我收到运行时错误“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
如果组合框控件的
RowSource
属性正在使用,尝试设置 List
属性将触发运行时错误 70。
Private Sub CommandButton1_Click()
Me.ComboBox1.List = Range("D1:E3").Value
End Sub
要解决此问题,请在设置
RowSource
属性之前添加一行代码来重置 List
属性,或在 VBE 中进行必要的调整。
Private Sub CommandButton1_Click()
Me.ComboBox1.RowSource = ""
Me.ComboBox1.List = Range("D1:E3").Value
End Sub