Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3594
  • Last Modified:

How can I return the ListIndex value of an item in a Listbox on an Excel VBA user form ?

Hi Experts,

I have an Excel VBA User form with a Listbox control (called 'liSales').

I want to search through the Listbox items on the first field (Invoice number, actually) and return the ListIndex value when a matching entry is found.

What is the most efficient way of coding this ?

Thanks
Toco
0
Tocogroup
Asked:
Tocogroup
1 Solution
 
Rgonzo1971Commented:
Hi

pls try

Dim i   As Long
Found = False
With Me.liSales
    For i = 0 To .ListCount - 1 
        If .List(i, 1)  = "Your Value" Then 
            Idx = i
            Found = True
        End If 
    Next 
End With

Open in new window

Regards
0
 
TocogroupAuthor Commented:
Thanks for that. I didn't realise you could access the list in the listbox as if it was an array.
Regards
Toco
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now