|
-
Sep 6th, 2005, 09:46 AM
#1
Thread Starter
Junior Member
Creating a search function
Hi, I am trying to create a search function for my spreadsheet. I have created the code that takes the users input i.e. 200 and searches the worksheet for it and returns all of the different rows that have the value of 200 for example. See code below. I now need to be able to let the user select an item the search function returns to the list box and then either click on a button to edit it which would then bring up the data input userform and populate it from the details of the selected item from the worksheet, or simply just go to that row on the worksheet.
Any ideas how I can link the row number to a hidden list box column and then use this to enter the details back into the userform ready to be edited by the user?
Thanks for your help. Aaron
Private Sub Search_Click()
Dim sht As Worksheet
Dim lngMaxRows As Long, lngRow As Long 'lngMaxRows = total rows
Dim lngItem As Long
Dim SearchTextBox As Long
Sheets("Month").Activate
Set sht = ActiveSheet
QuerySearch.DisplayResults.Clear ' Clears the display results listbox in userform
lngMaxRows = Cells(65535, 13).End(xlUp).Row ' Works out what the last row is
For lngRow = 1 To lngMaxRows ' Checks from row 1 to lngMaxRow defined above
If QuerySearch.SearchTextBox.Text = sht.Cells(lngRow, 13).Value Then
DisplayResults.AddItem ""
lngItem = QuerySearch.DisplayResults.ListCount - 1
QuerySearch.DisplayResults.ColumnHeads = True
' Adds columns on the worksheet to cells in the listbox
QuerySearch.DisplayResults.Column(0, lngItem) = sht.Cells(lngRow, 13)
QuerySearch.DisplayResults.Column(1, lngItem) = sht.Cells(lngRow, 4)
QuerySearch.DisplayResults.Column(2, lngItem) = sht.Cells(lngRow, 7)
QuerySearch.DisplayResults.Column(3, lngItem) = sht.Cells(lngRow, 8)
End If
Next
Set sht = Nothing
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|