Combobox下拉显示在其他工作表中

时间:2016-09-23 18:04:00

标签: excel vba excel-vba combobox

我有一个带有搜索建议的组合框,下面是代码:

http://trumpexcel.com/2013/10/excel-drop-down-list-with-search-suggestions/

效果很好,但是当我在另一张纸上并按“Enter”时,搜索字段随机弹出工作表enter image description here

它甚至不是完整的盒子,只是蓝色的场

有关禁用它的任何见解?我唯一的成功就是将计算转为手动,但工作簿需要自动计算

谢谢!

3 个答案:

答案 0 :(得分:1)

我在自己的智能搜索栏的VBA版本中遇到了类似的问题。我如何修复它是通过执行以下操作:

Private Sub ComboBox1_Change()
    If ComboBox1.Value = "" Then Exit Sub '<------ Problem solved.
    ComboBox1.ListFillRange = "DropDownList"
    Me.ComboBox1.DropDown
End Sub

OR

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    Dim SheetWithComboBox As Worksheet: Set SheetWithComboBox = ThisWorkbook.Sheets(1)

    If ThisWorkbook.ActiveSheet.Name <> SheetWithComboBox.Name Then
        ComboBox1.Visible = False
    Else: ComboBox1.Visible = True
    End If
End Sub

答案 1 :(得分:1)

@Tyeler

感谢您的帮助,您的想法帮助我想到了一种方式

Private Sub ComboBox1_change()
 Dim sht1 As Worksheet
 Set sht1 = Worksheets("xxx")

 If ThisWorkbook.ActiveSheet.Name = sht1.Name Then

ComboBox1.ListFillRange = "DropDownList"
Me.ComboBox1.DropDown
Call macro1
Else: Exit Sub
End If

End Sub

答案 2 :(得分:0)

我找到了一个解决方案,至少对我来说,适用于所有工作表。

Private Sub Combobox_Get_Focus() 

    ComboBox1.ListFillRange = "DropDownList" 
    Me.ComboBox1.DropDown 

End Sub