2013-10-29 92 views
0

有一個問題,有可能以某種方式跳轉到特定列表框中的某個索引,如下圖所示?跳轉到列表框中的項目

enter image description here

我已經嘗試下面的代碼

但它驅使我您已經使用ListIndex屬性不正確

一個屬性我的清單錯誤這可能很重要。

行來源類型:表/查詢

在此先感謝您。

+0

什麼是你想再做選擇?跳轉到具體的索引如何?通過在文本框中輸入內容並將其與列表中的項目進行匹配? – 2013-10-29 12:16:39

+0

確切@mehow,但我不知道是否有可能使用Row/Table類型的查詢。 – unpix

+0

是我的答案你想要什麼? – 2013-10-29 12:23:50

回答

2

嘗試ListBox.Selected(index) = True。如果它是多選列表框,則還需要遍歷其他元素並以相同方式取消選擇它們。

1

創建一個標準模塊的代碼

Sub Main() 
    UserForm1.Show 
    Unload UserForm1 
End Sub 

插入一個窗體,並在視覺上做類似

enter image description here

走進用戶窗體代碼,並添加

Private Sub CommandButton1_Click() 

    Dim v As Long 
    For v = 0 To ListBox1.ListCount - 1 
     If TextBox1 = ListBox1.List(v) Then 
      ListBox1.Selected(v) = True 
     End If 
    Next v 

End Sub 

Private Sub UserForm_Initialize() 

    With ListBox1 
     .AddItem ("text1") 
     .AddItem ("text2") 
     .AddItem ("text3") 
    End With 

End Sub 

運行Main

的框中鍵入:text2

text2將在列表中

enter image description here

相關問題