Reputation: 853
One question, it is possible to jump somehow to a certain index in a specif listbox as in the image below?
I already tried the following code
Listbox.ListIndex = index
But it drives me to the error You've used the ListIndex property incorrectly
One property of my list that might be important to mention.
Row source type : Table/Query
Thank you in advance.
Upvotes: 0
Views: 1327
Reputation:
Create a standard module with the code
Sub Main()
UserForm1.Show
Unload UserForm1
End Sub
Insert a userform and visually do something like
Go into the userform code and add
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
Run Main
Macro
Type in the box : text2
The text2
will be selected in the list
Upvotes: 1
Reputation: 17475
Try ListBox.Selected(index) = True
. If it is a multiselect listbox, you also need to loop through the other elements and unselect them in the same way.
Upvotes: 2