|
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.
|