tiny4725,
Attached is a modified version of your most recently posted workbook. I made several changes. First, I got rid of the 2nd userform, that was unnecessary. Here is the full code for the userform SearchForm:
Private Sub btn_Search_Click()
Dim rngFound As Range
Dim strFirst As String
If Len(Trim(Me.txt_SearchTerm.Text)) = 0 Then
Me.txt_SearchTerm.SetFocus
MsgBox "Must enter a search term", , "Search Error"
Exit Sub
End If
Set rngFound = Cells.Find(Me.txt_SearchTerm.Text)
If rngFound Is Nothing Then
Me.txt_SearchTerm.SetFocus
MsgBox "No items found contaning """ & Me.txt_SearchTerm.Text & """", , "Search Error"
Exit Sub
End If
Me.lbx_Results.Clear
strFirst = rngFound.Address
Do While Not rngFound Is Nothing
With Me.lbx_Results
.AddItem rngFound.Address(0, 0)
.List(.ListCount - 1, 1) = rngFound.Text
End With
Set rngFound = Cells.Find(Me.txt_SearchTerm.Text, rngFound)
If rngFound.Address = strFirst Then Exit Do
Loop
Me.lbx_Results.SetFocus
End Sub
Private Sub lbx_Results_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Range(Me.lbx_Results.Value).Select
Unload Me
End Sub
Private Sub UserForm_Terminate()
Unload Me
End Sub
Changes made to the userform:- Changed the naming convention for the controls
- Removed the frame
- Setup a proper tab order
- Made the search button the Default so that pressing enter causes that button's code to run
- Double-clicking a search result item will still take you to that cell and close the userform
- The listbox is now a 2 column listbox. The first column contains the cell address, the second column contains the dislpay text of the cell
Bookmarks