View Single Post
  #2  
Old 07-04-2009, 07:03 PM
Keyur Keyur is offline
Registered User
 
Join Date: 31 Mar 2004
Location: Toronto, Canada
MS Office Version:2003/2007
Posts: 36
Keyur is becoming part of the community
Re: searchmacro doen't work when initiated from listbox

Hey WCJanssen

the search doesn't works because of the way you fill the list box with the code below
Code:
Private Function CvtRowValues(rowNumber As Long) As String
    Dim column As Integer
    CvtRowValues = ""
    For column = 1 To 1
        CvtRowValues = CvtRowValues & " " & Cells(rowNumber, column).Value
    Next
End Function
You are adding a space " " before the value so when you search using the selected item it's looking for value a space in front and so the search fails.

You do not need For Next Loop in this case. Simply put

Code:
Private Function CvtRowValues(rowNumber As Long) As String
    Dim column As Integer
    CvtRowValues = ""
    CvtRowValues =  Cells(rowNumber, column).Value
End Function
You probably do not even need another private function. you can use your additem line as

Code:
ListBoxSpec.AddItem Cells(vFound.Row, 1).Value
Another thing I noticed is that you do not need any of your Do While Loops, unless you posted a simplified version of your spreadsheet.

Now for whatever reason if you want leave the space you can use LTrim(ListBoxSpec.Value) function under your Find statement for it to work.

Hope this helps.
Reply With Quote