Autofreak
02-22-2006, 01:05 PM
Hello All,
can't figure out why VBA would not set my_Box to UserForm1.ListBox1 - "Type mismatch" tried diffrent ways, no result. Here I want to use the function below to return an item's index in ListBox1.
Thank you!
Serge
Sub getListBoxItem()
Dim my_form As UserForm
Dim my_Box As ListBox
Set my_form = UserForm1
Set my_Box = UserForm1.ListBox1
MsgBox GetItemIndex(my_Box, "account")
End Sub
Private Function GetItemIndex(ByVal lb As ListBox, ByVal item As String) As Integer
Dim i As Integer
item = LCase(item)
For i = 0 To lb.ListCount - 1
If LCase(lb.List(i)) = item Then
GetItemIndex = i
Exit Function
End If
Next
GetItemIndex = -1
End Function
can't figure out why VBA would not set my_Box to UserForm1.ListBox1 - "Type mismatch" tried diffrent ways, no result. Here I want to use the function below to return an item's index in ListBox1.
Thank you!
Serge
Sub getListBoxItem()
Dim my_form As UserForm
Dim my_Box As ListBox
Set my_form = UserForm1
Set my_Box = UserForm1.ListBox1
MsgBox GetItemIndex(my_Box, "account")
End Sub
Private Function GetItemIndex(ByVal lb As ListBox, ByVal item As String) As Integer
Dim i As Integer
item = LCase(item)
For i = 0 To lb.ListCount - 1
If LCase(lb.List(i)) = item Then
GetItemIndex = i
Exit Function
End If
Next
GetItemIndex = -1
End Function