Search in Listview

maria90

New Member
Joined
Apr 9, 2012
Messages
38
Dear Excel wizards

I have a listview with six columns.

How do I search for a value in the first column?
I assume that it's column 0, isn't it?

Example to search for value 59:

Code:
FindItem "59", lvwCustomers, 0,

Code:
Public Sub FindItem(strSearch As String, lvw As ListView, iSubItemIndex As Integer, bExact As Boolean)


       For i = lvw.SelectedItem.Index + 1 To lvw.ListItems.count


            If (bExact And lvw.ListItems(i).SubItems(0) = strSearch) _
               Or InStr(lvw.ListItems(i).SubItems(0), strSearch) > 0 Then

                With lvw.ListItems(i)
                    .Selected = True
                    .EnsureVisible
                End With


                bFound = True
                Exit For


            End If
        Next


        If Not bFound Then
            MsgBox "Search Item'" & UCase$(strSearch) & "' not found..", vbInformation, ""


            'Go back to the start

            With lvw.ListItems(1)
                .Selected = True
                .EnsureVisible
            End With
        End If

I get invalid property value (at Subitems(0) )

Is there any other way to search for a value in the first column?

My second question about the listview is about the search type: Is possible to create a wildcard search or a 'like' search which searches for similar values?

Thanks

Maria
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
To search for a value in the first column, try...

Code:
lvw.ListItems(1).Text

For a wildcard search, you can use the LIKE operator...

Code:
If lvw.ListItems(1).Text Like "*" & strSearch & "*" Then

Hope this helps!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,222,749
Messages
6,167,958
Members
452,158
Latest member
MattyM

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top